Skip to content

Fix thread safety issue in resource changed callbacks during imports#107218

Closed
d6e wants to merge 1 commit intogodotengine:masterfrom
d6e:fix-resource-loader-thread-safety
Closed

Fix thread safety issue in resource changed callbacks during imports#107218
d6e wants to merge 1 commit intogodotengine:masterfrom
d6e:fix-resource-loader-thread-safety

Conversation

@d6e
Copy link
Copy Markdown

@d6e d6e commented Jun 6, 2025

Summary

Fixes a segmentation fault that occurs when font resources are imported in background threads and emit “changed” signals that trigger thread-unsafe node operations.

Problem

When importing font files, the ResourceLoader can emit “resource changed” callbacks from background threads. These callbacks may be connected to GUI nodes (for example, RichTextLabel) that perform operations requiring main‐thread access, causing thread‐safety violations and crashes.

The specific error trace is:

ERROR: Caller thread can't call this function in this node (/root). Use call_deferred() or call_thread_group() instead.
    at: propagate_notification (scene/main/node.cpp:2523)

Solution

Modify ResourceLoader::resource_changed_emit() to use call_deferred() instead of a direct call() when invoking callbacks. This ensures all “resource changed” signals run on the main thread, preventing thread‐safety violations.

Use call_deferred() instead of direct call() in ResourceLoader::resource_changed_emit() to ensure resource change callbacks execute on the main thread. This prevents segfaults when font imports trigger node operations from background threads.
@d6e
Copy link
Copy Markdown
Author

d6e commented Jun 6, 2025

Closed because #107224 supersedes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants