Avoid crash on exiting due to late prints #80161
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #80152.
UPDATE: Probably fixes #79379.
Bugsquad edit: And fixes #79506.
The MRP there adds a message when the
EditorNode
has already been destroyed. The most obvious fix is done here, which is just validating the singleton when a deferred call happens. The problem is that static calls in the message queue can't be validated.Now, there are potential alternatives to this fix that may be done instead of in addition:
a) Let the static callables have some sort of custom validation.
For instance, there's this call:
callable_mp_static(&EditorNode::_print_handler_impl).bind(p_string, p_error, p_rich).call_deferred();
With this approach it could become something like this:
callable_mp_static(&EditorNode::_print_handler_impl).bind(p_string, p_error, p_rich).add_validator([]() -> bool{ return EditorNode::get_singleton(); }).call_deferred();
b) Like a), but using a sentinel pointer:
callable_mp_static(&EditorNode::_print_handler_impl).bind(p_string, p_error, p_rich).add_validity_sentinel(&EditorNode::singleton).call_deferred();
c) Make all deferred calls of this kind via the object instance instead of static. That would enable the current validated call mechanism to do its magic.