diff --git a/core/object/message_queue.cpp b/core/object/message_queue.cpp index decf030e27c..627de9042bb 100644 --- a/core/object/message_queue.cpp +++ b/core/object/message_queue.cpp @@ -324,19 +324,18 @@ MessageQueue::~MessageQueue() { while (read_pos < buffer_end) { Message *message = (Message *)&buffer[read_pos]; + read_pos += sizeof(Message); + Variant *args = (Variant *)(message + 1); int argc = message->args; if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { for (int i = 0; i < argc; i++) { args[i].~Variant(); } + read_pos += sizeof(Variant) * argc; } - message->~Message(); - read_pos += sizeof(Message); - if ((message->type & FLAG_MASK) != TYPE_NOTIFICATION) { - read_pos += sizeof(Variant) * message->args; - } + message->~Message(); } singleton = nullptr; diff --git a/core/object/message_queue.h b/core/object/message_queue.h index ceb6f2a3f1b..ae2a21ef09d 100644 --- a/core/object/message_queue.h +++ b/core/object/message_queue.h @@ -55,9 +55,9 @@ class MessageQueue { struct Message { Callable callable; - int16_t type; + int16_t type = 0; union { - int16_t notification; + int16_t notification = 0; int16_t args; }; };