diff --git a/core/object/message_queue.cpp b/core/object/message_queue.cpp index 83e0c4aea1..cfd8904af6 100644 --- a/core/object/message_queue.cpp +++ b/core/object/message_queue.cpp @@ -62,15 +62,16 @@ Error CallQueue::push_set(Object *p_object, const StringName &p_prop, const Vari } Error CallQueue::push_callablep(const Callable &p_callable, const Variant **p_args, int p_argcount, bool p_show_error) { - mutex.lock(); uint32_t room_needed = sizeof(Message) + sizeof(Variant) * p_argcount; ERR_FAIL_COND_V_MSG(room_needed > uint32_t(PAGE_SIZE_BYTES), ERR_INVALID_PARAMETER, "Message is too large to fit on a page (" + itos(PAGE_SIZE_BYTES) + " bytes), consider passing less arguments."); + mutex.lock(); + _ensure_first_page(); if ((page_offset + room_needed) > uint32_t(PAGE_SIZE_BYTES)) { - if (room_needed > uint32_t(PAGE_SIZE_BYTES) || pages_used == max_pages) { + if (pages_used == max_pages) { ERR_PRINT("Failed method: " + p_callable + ". Message queue out of memory. " + error_text); statistics(); mutex.unlock();