Browse Source

Do not allow adding tasks while in the middle of flushing a message queue

Juan Linietsky 6 years ago
parent
commit
4bb0080b3d
3 changed files with 18 additions and 0 deletions
  1. 9 0
      core/message_queue.cpp
  2. 4 0
      core/message_queue.h
  3. 5 0
      editor/progress_dialog.cpp

+ 9 - 0
core/message_queue.cpp

@@ -271,6 +271,8 @@ void MessageQueue::flush() {
 	//using reverse locking strategy
 	_THREAD_SAFE_LOCK_
 
+	flushing = true;
+
 	while (read_pos < buffer_end) {
 
 		//lock on each iteration, so a call can re-add itself to the message queue
@@ -327,13 +329,20 @@ void MessageQueue::flush() {
 	}
 
 	buffer_end = 0; // reset buffer
+	flushing = false;
 	_THREAD_SAFE_UNLOCK_
 }
 
+bool MessageQueue::is_flushing() const {
+
+	return flushing;
+}
+
 MessageQueue::MessageQueue() {
 
 	ERR_FAIL_COND(singleton != NULL);
 	singleton = this;
+	flushing = false;
 
 	buffer_end = 0;
 	buffer_max_used = 0;

+ 4 - 0
core/message_queue.h

@@ -72,6 +72,8 @@ class MessageQueue {
 
 	static MessageQueue *singleton;
 
+	bool flushing;
+
 public:
 	static MessageQueue *get_singleton();
 
@@ -87,6 +89,8 @@ public:
 	void statistics();
 	void flush();
 
+	bool is_flushing() const;
+
 	int get_max_buffer_usage() const;
 
 	MessageQueue();

+ 5 - 0
editor/progress_dialog.cpp

@@ -166,6 +166,11 @@ void ProgressDialog::_popup() {
 
 void ProgressDialog::add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) {
 
+	if (MessageQueue::get_singleton()->is_flushing()) {
+		ERR_PRINT("Do not use progress dialog (task) while flushing the message queue or using call_deferred()!");
+		return;
+	}
+
 	ERR_FAIL_COND(tasks.has(p_task));
 	ProgressDialog::Task t;
 	t.vb = memnew(VBoxContainer);