Skip to content

[3.x] Don't terminate library if other GDNatives are still using it #49467

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions modules/gdnative/gdnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,13 @@ bool GDNative::initialize() {
#endif

if (library->should_load_once()) {
if (GDNativeLibrary::loaded_libraries.has(lib_path)) {
Map<String, Vector<Ref<GDNative>>>::Element *V = GDNativeLibrary::loaded_libraries.find(lib_path);
if (V) {
// already loaded. Don't load again.
// copy some of the stuff instead
this->native_handle = GDNativeLibrary::loaded_libraries[lib_path][0]->native_handle;
Vector<Ref<GDNative>> &gdnatives = V->get();
gdnatives.push_back(Ref<GDNative>(this));
this->native_handle = gdnatives[0]->native_handle;
initialized = true;
return true;
}
Expand Down Expand Up @@ -430,6 +433,10 @@ bool GDNative::terminate() {
gdnatives->clear();
// whew this looks scary, but all it does is remove the entry completely
GDNativeLibrary::loaded_libraries.erase(GDNativeLibrary::loaded_libraries.find(library->get_current_library_path()));
} else {
// in case user triggers a call to terminate in the callback below
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// in case user triggers a call to terminate in the callback below
// In case user triggers a call to terminate in the callback below.

Per the comment style.

WARN_PRINT("loaded_libraries is empty, avoiding recursive call to `GDNative::terminate`");
return false;
}
}

Expand Down