I have a scene with a start calculation button and when press it will loop x number of times to perform calculation.
Example code,

for i in total:
  calc()

Whenever total exceed 25 there will be error of Message queue out of memory.
Below is the detail from error log,

Failed method: Label:_update_callback target ID: 363597
TOTAL BYTES: 4194288
NULL count: 0
CALL _update_callback: 87381
CALL _sort_children: 4
CALL _update_minimum_size: 87377
ERROR: Message queue out of memory. Try increasing 'memory/limits/message_queue/max_size_kb' in project settings.
   at: push_call (core/message_queue.cpp:54) - Method failed. Returning: ERR_OUT_OF_MEMORY

Looks like the error occurs at Label:_update_callback and I wonder why?

  • I'm bored, so I feel like a little source code digging...

    The error is saying the memory queue ran out of memory in _update_callback.
    The only _update_callback I can find in the Godot 3 source is in CanvasItem.
    Whenever a canvasitem is updated, it pushes a call to _update_callback onto the message queue.
    The message queue has a maximum size of 4194304 bytes (4MB).

    So I'm going to guess that something in calc() is updating a huge number of canvas items in one hit, which is filling up the queue too fast before the main engine loop can do a flush.
    Resizing a canvasitem can trigger an update, or changing the visibility of a canvas item will recursively update every child item without a flush inbetween.

    Or I'm totally wrong. But I'm guessing its related to a large number of canvas item updates happening (directly, or indirectly) in the loop.

What is total? If you want to use it as a number, you'd use range.

for i in range(10):
    # loop 10 times

If total is an Array, then you could do this:

for i in range(total.size()):
    # loop for each element in total

Assuming you don't need the value of the elements in total.

    I'm bored, so I feel like a little source code digging...

    The error is saying the memory queue ran out of memory in _update_callback.
    The only _update_callback I can find in the Godot 3 source is in CanvasItem.
    Whenever a canvasitem is updated, it pushes a call to _update_callback onto the message queue.
    The message queue has a maximum size of 4194304 bytes (4MB).

    So I'm going to guess that something in calc() is updating a huge number of canvas items in one hit, which is filling up the queue too fast before the main engine loop can do a flush.
    Resizing a canvasitem can trigger an update, or changing the visibility of a canvas item will recursively update every child item without a flush inbetween.

    Or I'm totally wrong. But I'm guessing its related to a large number of canvas item updates happening (directly, or indirectly) in the loop.

    cybereality What is total? If you want to use it as a number, you'd use range.
    for i in range(10):

    This works too:

    for i in 10:
        print(i)

    I didn't know that worked until I saw this topic and tried it.

    Just found the root cause. I was updating the calculation results to a group of labels and these labels were accidentally re-created in every loop. After i changed to only update and not recreating the labels the error is gone.
    Thanks to everyone who replied and tried to help 🙂