-
Notifications
You must be signed in to change notification settings - Fork 212
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
Fix tests with Godot 3.3 #746
Conversation
Fixes crashes due to hot-reloading changes in godot 3.3 that cause reloadable libraries to be terminated when no NativeScripts remain referencing them.
This should probably be included for #733 if we're planning for godot-rust 0.9.4 to support Godot 3.3 |
Could you elaborate? It's part of the contract for Godot to at least call |
@toasteater Godot must call |
The bug ironically means that |
I'm not sure how the code and comments there are related to calling Of course there are some engine bugs we just have to work around due to compatibility, like the
What about making a PR to the engine with those couple lines of code, maybe? |
Sorry, yeah, this wasn't a super clear way to explain it. Basically, it wasn't relevant to
Just did this: godotengine/godot#49467 I could drop that commit from this PR and make a separate PR when we get a response on godotengine/godot#49467 if you want. Again, the main thing needed here is to make the gdnlib not-reloadable. |
@Waridley I think it's best to drop that commit for now. I'm yet to spend enough time to look at the situation but frankly, it looks like kludge. We want to find a way to at least recognize it when the init function is called for a second time and do proper cleanup. Hiding the error in the cheapest way possible would not help. |
rebased on godot-rust#746 & godot-rust#748 and squashed. Still writing more tests & awaiting final status on those PR's
rebased on godot-rust#746 & godot-rust#748 and squashed. Still writing more tests & awaiting final status on those PR's
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.
Looks good to me. Thanks!
bors r+
746: Fix tests with Godot 3.3 r=toasteater a=Waridley The most important change here is the first commit making the `.gdnlib` file not-reloadable. Godot 3.3 apparently added hot-reloading support for gdnative, but did so by terminating the library when no `NativeScript`s reference it: https://github.com/godotengine/godot/blame/3.3/modules/gdnative/nativescript/nativescript.cpp#L1550 This probably makes sense for most users, but for the specific case of keeping a `GDNative` object alive while `NativeScript`s are created and freed, this causes the library to be terminated out from under the `GDNative` object This is actually supposed to be prevented, but is not due to a bug in the engine. However even fixing that bug upstream would still cause panics in the tests due to the godot-rust class registry thinking all classes have already been registered when `godot_nativescript_init` is called again. Therefore, I also included a commit that refactors the `init` code a bit to only panic if a class is registered *with the same init handle* more than once, just in case users have a use case where making the library not-relodable is not an option for some reason. This adds a lifetime parameter to `InitHandle` in order to keep it `Copy`, but that does not seem to break any of my code or the tests. There was also a superfluous error in the `test_vararray_return_crash` test due to the camera not being in the world. This may not matter for the test, but I figured it was somewhat confusing that it was not included in the "expected error messages" list. These changes were kept as separate commits so you can let me know if you want to forego or modify any of them. Co-authored-by: Waridley <[email protected]>
Build failed: |
The |
@toasteater Weird... It worked on my machine. I'll try to figure out why it failed, and whether there's a more robust way to avoid the error, or if it really even matters. Part of me worries that it returning a default value might obscure the possibility of a crash, but I may not be fully understanding the test. But on that note, could it make sense for most tests and the |
@Waridley The original crash was caused by an inconsistency in the GDNative glue code, where for some C++ types mapping to
The panic is always printed in the log, just not immediately above the stacktrace, for some reason:
|
Alright, I think I'll drop this one as well for now. Though I wish I knew why it panicked.
Oh! I see. Weird. |
bors retry |
Build succeeded: |
The most important change here is the first commit making the
.gdnlib
file not-reloadable. Godot 3.3 apparently added hot-reloading support for gdnative, but did so by terminating the library when noNativeScript
s reference it: https://github.com/godotengine/godot/blame/3.3/modules/gdnative/nativescript/nativescript.cpp#L1550This probably makes sense for most users, but for the specific case of keeping a
GDNative
object alive whileNativeScript
s are created and freed, this causes the library to be terminated out from under theGDNative
object This is actually supposed to be prevented, but is not due to a bug in the engine. However even fixing that bug upstream would still cause panics in the tests due to the godot-rust class registry thinking all classes have already been registered whengodot_nativescript_init
is called again. Therefore, I also included a commit that refactors theinit
code a bit to only panic if a class is registered with the same init handle more than once, just in case users have a use case where making the library not-relodable is not an option for some reason. This adds a lifetime parameter toInitHandle
in order to keep itCopy
, but that does not seem to break any of my code or the tests.There was also a superfluous error in the
test_vararray_return_crash
test due to the camera not being in the world. This may not matter for the test, but I figured it was somewhat confusing that it was not included in the "expected error messages" list.These changes were kept as separate commits so you can let me know if you want to forego or modify any of them.