-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Docs state that object.free() will make any reference to the object return null. This is not true. #35534
Comments
Sorry, this is kind of a duplicate, couldn't find it at first: #20549 Anyway. To reiterate my view: It seems the dead object still has some uses - purely as a reference. So .. In either case, the what the docs state is either plain wrong or at least confusing. |
The docs will probably become completely true with the merging of #35667 |
In 58cbec8 they print as |
My guess is that the documentation is ahead of implementation - since this was added recently, and there's a potential solution pending as Zireael07 pointed out. |
The one I pointed out was cancelled, and later another fix was made. |
Duplicate of #20549. |
Or well, not a duplicate if we consider that this one is about invalid docs while the other is a feature request. |
Nice to know it's being worked on. Well, at the time of opening #20549, the docs were up to date in regards to this. :) I'd like this feature, but before it appears, I guess this issue is about invalid docs. (So anyone wondering about it, might end up reading this discussion and conclude that the feature will likely(?) appear later.) |
It's not clear whether #20549 will be implemented. What has been fixed is the problem of dangling Variants where a reference to a freed object could become a reference to a valid, different object. |
This should probably closed seeing as the mentionned PR is merged. |
Yep, this is resolved. |
Godot version:
3.2. beta5
OS/device including version:
Win10
Issue description:
The docs state that calling
free()
:However, after an object has been freed, references to it will not return
null
but instead an object (printing it will give[Deleted Object]
). So!!object_ref
returnstrue
and notfalse
which it does fornull
. I think it would be much more useful to actually returnnull
(-->false
as a boolean), like is clearly documented. Edit: --> So, only two states:null
and[Object]
, so that there's no need to handle the third[Deleted Object]
case (which is practically null, but currently technically not).As this is such a basic thing, I'm probably missing something obvious. Anyhow, the latter part of the doc description was added in 3.1 (not there in 3.0), but this happens at least in 3.1.2 stable official and 3.2 beta5, and any earlier I've tried.
Steps to reproduce:
var my_object = some_object_class.new()
my_object.free()
print(my_object)
orprint(!!my_object)
Minimal reproduction project:
FreedButNotNull.zip
Workarounds:
In my case, now considering to either do a special validation, eg.
is_instance_valid(object)
, or attaching to the virtual_notify
method of the important objects that might be deleted to check for NOTIFICATION_PREDELETE to tell others so they don't need to useis_instance_valid
. For Nodes especially, the_notify
is quite crowded, so it's not an optimal workaround (and for Nodes_exit_tree
is not always an alternative: it might be called more often). So, hoping this is a bug.The text was updated successfully, but these errors were encountered: