migueldeicaza / SwiftGodot

New Godot bindings for Swift
https://migueldeicaza.github.io/SwiftGodotDocs/tutorials/swiftgodot-tutorials/
MIT License
1.07k stars 70 forks source link

Use alternative for isInstanceValid #505

Closed migueldeicaza closed 1 month ago

migueldeicaza commented 2 months ago

See this bug:

https://github.com/godotengine/godot-cpp/pull/1513

We could keep in our binding the API, but rather than invoking this method directly, we would provide the implementation that queries the database, and that would preserve compatibility, while giving us the correct behavior.

dsnopek commented 1 month ago

I don't know much about the Swift bindings, but it's entirely possible that is_instance_valid is fine to use with Swift.

In godot-cpp, the problem is that developers can have Object *s, and if it was deleted, and then developer calls is_instance_valid() with that pointer, it can't actually look up the Godot-side object, because that memory is no longer valid. If we instead mandated that developers use a smart pointer-like type (rather than raw pointers), then we could implement a safe way to use is_instance_valid(), but we're not going to do that because we want have API parity with Godot modules.

So, this might not be an issue with the Swift bindings?

migueldeicaza commented 1 month ago

Thanks for the clarity, I think we might be fine, my concern was that perhaps there was a scenario where the object was destroyed in the Godot side, but our callback was not invoked.

dsnopek commented 1 month ago

my concern was that perhaps there was a scenario where the object was destroyed in the Godot side, but our callback was not invoked

Nope, I'm not aware of any such scenario

migueldeicaza commented 1 month ago

Thank you David, I am going to close this now.