You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, is_instance_valid() dereferences object pointers passed to it due to implicit cast to Variant. As such, executing is_instance_valid() on freed nodes, unlike in gdscript, causes a use-after-free crash. Currently, there doesn't seem to be a way to store nodes where UtilityFunctions::is_instance_valid() can work without sacrificing typing (by storing everything as Variant), and the example project simply uses pointers for passing around object pointers as well.
Steps to reproduce
Call UtilityFunctions::is_instance_valid() on a freed node pointer. The program crashes instead of returning false.
Minimal reproduction project
See steps to reproduce.
The text was updated successfully, but these errors were encountered:
In a C++ module, rather than using is_instance_valid(), in situations where you need to store objects that might get freed, you'd store ObjectID and call ObjectDB::get_instance() to check if it's still valid. This is what I'd recommend doing in godot-cpp as well, since we are attempting to emulate modules (and it doesn't suffer from the problem you're encountering).
Regarding fixing is_instance_valid(): I wonder if we should just not expose it in godot-cpp?
There is no way to check if an Object * has been freed, and trying to create a Variant from a freed Object * will cause a crash. This is exactly what will happen if you call is_instance_valid() with a freed Object * (it's automatically converted to Variant), which that function is practically inviting developers to do. This isn't the first time this issue has come up. :-)
Godot version
4.2.1.stable
godot-cpp version
4.2.1.stable
System information
Any
Issue description
Currently,
is_instance_valid()
dereferences object pointers passed to it due to implicit cast to Variant. As such, executingis_instance_valid()
on freed nodes, unlike in gdscript, causes a use-after-free crash. Currently, there doesn't seem to be a way to store nodes where UtilityFunctions::is_instance_valid() can work without sacrificing typing (by storing everything as Variant), and the example project simply uses pointers for passing around object pointers as well.Steps to reproduce
Call
UtilityFunctions::is_instance_valid()
on a freed node pointer. The program crashes instead of returning false.Minimal reproduction project
See steps to reproduce.
The text was updated successfully, but these errors were encountered: