Do not allow adding tasks while in the middle of flushing a message queue
This commit is contained in:
parent
c6b587636b
commit
4bb0080b3d
3 changed files with 18 additions and 0 deletions
|
@ -271,6 +271,8 @@ void MessageQueue::flush() {
|
||||||
//using reverse locking strategy
|
//using reverse locking strategy
|
||||||
_THREAD_SAFE_LOCK_
|
_THREAD_SAFE_LOCK_
|
||||||
|
|
||||||
|
flushing = true;
|
||||||
|
|
||||||
while (read_pos < buffer_end) {
|
while (read_pos < buffer_end) {
|
||||||
|
|
||||||
//lock on each iteration, so a call can re-add itself to the message queue
|
//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
|
buffer_end = 0; // reset buffer
|
||||||
|
flushing = false;
|
||||||
_THREAD_SAFE_UNLOCK_
|
_THREAD_SAFE_UNLOCK_
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MessageQueue::is_flushing() const {
|
||||||
|
|
||||||
|
return flushing;
|
||||||
|
}
|
||||||
|
|
||||||
MessageQueue::MessageQueue() {
|
MessageQueue::MessageQueue() {
|
||||||
|
|
||||||
ERR_FAIL_COND(singleton != NULL);
|
ERR_FAIL_COND(singleton != NULL);
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
flushing = false;
|
||||||
|
|
||||||
buffer_end = 0;
|
buffer_end = 0;
|
||||||
buffer_max_used = 0;
|
buffer_max_used = 0;
|
||||||
|
|
|
@ -72,6 +72,8 @@ class MessageQueue {
|
||||||
|
|
||||||
static MessageQueue *singleton;
|
static MessageQueue *singleton;
|
||||||
|
|
||||||
|
bool flushing;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static MessageQueue *get_singleton();
|
static MessageQueue *get_singleton();
|
||||||
|
|
||||||
|
@ -87,6 +89,8 @@ public:
|
||||||
void statistics();
|
void statistics();
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
|
bool is_flushing() const;
|
||||||
|
|
||||||
int get_max_buffer_usage() const;
|
int get_max_buffer_usage() const;
|
||||||
|
|
||||||
MessageQueue();
|
MessageQueue();
|
||||||
|
|
|
@ -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) {
|
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));
|
ERR_FAIL_COND(tasks.has(p_task));
|
||||||
ProgressDialog::Task t;
|
ProgressDialog::Task t;
|
||||||
t.vb = memnew(VBoxContainer);
|
t.vb = memnew(VBoxContainer);
|
||||||
|
|
Loading…
Reference in a new issue