-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Change _can_handle
and _edit
virtual methods to take Object*
#66121
Change _can_handle
and _edit
virtual methods to take Object*
#66121
Conversation
editor/editor_plugin.cpp
Outdated
if (p_object->is_class("Resource")) { | ||
GDVIRTUAL_CALL(_edit, Ref<Resource>(Object::cast_to<Resource>(p_object))); | ||
} else { | ||
GDVIRTUAL_CALL(_edit, p_object); | ||
} | ||
GDVIRTUAL_CALL(_edit, p_object); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the behavior, no? How does this affect existing plugins and the actual reference counting on that resource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think it is supposed to change behavior, it's passed just the same as every other virtual method taking Object*
already. If reference count has to increase, it will happen in the callee.
The reason it takes Variant is because, if you are editing a Ref<> type, it properly passes the reference counter. If you pass a pointer, you may miss it until you re assign it to something. Not sure if in practice it makes any difference. |
My understanding is that it really makes no practical difference because in every case if the callee wants to store it, it should be using a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine. RefCounted
object's reference count is respected through the GDVIRTUAL_CALL()
. Using Variant
was incrementing it to later decrement back on return, which didn't really add any value (maybe in past codebases that had a role?). Moreover, if the call chain required the cast, handles()
would already be in trouble. I agree with @Zylann in that the callee is the responsible for keeping the object referenced if it needs to. In any case, doing the cast wasn't really woking as a safety measure, preventing a failure to do so from causing trouble.
@Zylann Could you rebase this PR? Edit: Did it myself to be able to merge this today. |
066f44f
to
d2b4e30
Compare
Thanks! |
Not sure why they were taking
Variant
while it's always been for Objects and other related virtual methods takeObject*
already.