-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix CanvasItem notification thread guard #80752
Conversation
It looks to me like this was done like this on purpose, not as a typo. See 0a9f72d where both Control and CanvasItem were made to use @@ -363,6 +379,7 @@ void CanvasItem::_window_visibility_changed() {
}
void CanvasItem::queue_redraw() {
+ ERR_THREAD_GUARD; // Calling from thread is safe.
if (!is_inside_tree()) {
return;
} So this should be discussed with @reduz. |
Given that functions like Therefore, my strong guess is that |
Maybe this is a problem of granularity. |
@akien-mga @bitsawer This is intended, GUI code (control derived) can't use thread groups. I wrote and explained this in detail in the guidelines regarding thread groups (they should probably be made into documentation I guess). @RandomShaper The guard you are mentioned in |
Maybe the |
I'm just making sure, but as Node2D inherits from CanvasItem, doesn't the current behavior basically mean that CanvasItem, Node2D or anything that inherits from them can't be used with thread groups? Currently, attaching a script with I'm also wondering because Node2D has less strict |
I am sorry, I misread the fix. This is perfect. |
Are you sure that's the right type of guard for every possible notification? Quoting myself:
Just to be sure. Elaborating: |
Reply from production chat:
So your call guys :) |
I think this PR is still worth merging, because currently using any 2D nodes with scripts using I also think that the best long-term solution will be to analyze each case and add more fine-grained access checks as already mentioned by RandomShaper. Ideally, the |
I quite don't see why not apply what I'm suggesting right in this PR and so have both the functionality and safety benefits. For me, that'd be the ground on top of which we could build something better. That said, I wouldn't oppose to it being merged, but I may do a follow-up PR with my take... 😀 |
Oh, I kind of missed that you were suggesting some additions to this PR, makes sense if you want to add something here. I think a more extensive follow up to add or tweak thread guards with some more thought is a good idea anyway, but I can add stuff here if you want to, feel free to hold my hand here. I guess you for example suggested ERR_THREAD_GUARD for CanvasItem NOTIFICATION_ENTER/EXIT_TREE, but doesn't basically all scene tree related manipulation require ERR_MAIN_THREAD_GUARD? I'm not all that familiar with this system yet, so you might be better at figuring out the level of checks needed. |
Scene tree manipulation methods (e.g., However, I've just realized there's more to it. Neither |
So what's the consensus? The merge window for this kind of "risky" change for 4.2 will soon close as we enter the beta phase and try to play it safe. |
Summarizing my take: My current take is to use |
Adding
I can go through all existing |
34df379
to
e30ec9d
Compare
Oh, you've already done. You're my hero! But I think the right kind of guard would be |
e30ec9d
to
12a2177
Compare
Updated most guards to use ERR_MAIN_THREAD_GUARD and pushed changes, except for Node3D NOTIFICATION_TRANSFORM_CHANGED. I played a bit safe not to change the existing logic much, but I guess we might as well go all in. What do you think about CanvasItem NOTIFICATION_VISIBILITY_CHANGED, in theory ERR_THREAD_GUARD might also be enough for it? edit: Slightly off topic, but I think currently some guards might also trigger for example when loading scenes using |
I think it's perfect now.
I think so. |
Thanks! |
Seems like simple fix, most other nodes like Node2D and Node3D also use
ERR_THREAD_GUARD
instead ofERR_MAIN_THREAD_GUARD
in their notification callback. Looks like CanvasItem should also useERR_THREAD_GUARD
unless there is some specific reason why CanvasItem can't be used with subthread groups.