Closed Humberd closed 3 years ago
How do you catch an exception?
try {
loginScene.free()
gameScene.free()
} catch (e: Throwable) {
}
I can't catch this error.
This exception is at closing of module. PackedScene inherits Reference, it should be free automatically. Maybe a problem with singleton cleaning ? Can you try in a classic object ?
Just like in the regular Godot, you can't use free on a Reference. If you try to free a PackedScene in GDScript you are going to get the same error. I think you can't catch it because the error is on the C++ side.
In the case of a reference, you just need to no longer have a variable pointing to it. Just make your variable a var and set it to null in collect. The same way I did in the example in the doc: https://godot-kotl.in/en/latest/advanced/kotlin-singleton/
Ah, forgot about singleton, assign it to null when cleaning
@CedNaru I still get the error
var loginScene = ResourceLoader.load("res://src/main/kotlin/clientjvm/scenes/login/LoginScene.tscn") as PackedScene?
override fun collect() {
loginScene = null
}
ERROR: MethodBind0<class Node>::call: Condition "!instance" is true. Returned: Variant()
At: D:\a\godot-kotlin-jvm\godot-kotlin-jvm\core\method_bind.gen.inc:132
Godot-JVM: Shutting down JVM ...
Ho this is interesting. Maybe it's because it's actually a Resource loaded from the disk so Godot already clean it because it's stored in a cache But the JVM instance still exists and when the JVM tried to unref it when it's closing you get that error because it's already dead. But just speculating, that's only the third issue that I have when dealing with Reference/Resources XD.
Just checked the GDScript behavior when you want to free a Reference
And yeah I got an error if I try to delete it directly:
Leaving that here as a memo. I wasn't sure anymore if it was a behavior we created ourselves or not. But not it's really from Godot.
Regarding the C++ error. It's just an error that Godot prints but it's not an exception and doesn't prevent the rest of the code to be executed. So there is nothing to catch in the first place.
I can't reproduce the issue I created this singleton
And the JVM shuts down just fine.
I did this and the problem is gone
private fun clearCurrentScene() {
if (node != null && GD.isInstanceValid(node)) {
node.queueFree()
}
node = null
}
@CedNaru did you create a node out of it? Because I did.
Let's say I've manually loaded a scene. How can I free it?
The problem is that when I do
loginScene.free()
, then I get this error:On the other hand if I don't free it, then I get this error: