Skip to content

Commit

Permalink
Merge pull request #84620 from dsnopek/gdextension-library-path-absolute
Browse files Browse the repository at this point in the history
Change `GDExtension`'s `library_path` back to an absolute path
  • Loading branch information
akien-mga committed Nov 9, 2023
2 parents a49b932 + 09fcc3a commit b06fe0d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/extension/gdextension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,11 @@ GDExtensionInterfaceFunctionPtr GDExtension::get_interface_function(StringName p
}

Error GDExtension::open_library(const String &p_path, const String &p_entry_symbol) {
library_path = p_path;

String abs_path = ProjectSettings::get_singleton()->globalize_path(p_path);
#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
// If running on the editor on Windows, we copy the library and open the copy.
// This is so the original file isn't locked and can be updated by a compiler.
bool library_copied = false;
if (Engine::get_singleton()->is_editor_hint()) {
if (!FileAccess::exists(abs_path)) {
ERR_PRINT("GDExtension library not found: " + library_path);
Expand All @@ -705,6 +704,7 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
return ERR_CANT_CREATE;
}
FileAccess::set_hidden_attribute(copy_path, true);
library_copied = true;

// Save the copied path so it can be deleted later.
temp_lib_path = copy_path;
Expand All @@ -714,12 +714,20 @@ Error GDExtension::open_library(const String &p_path, const String &p_entry_symb
}
#endif

Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true);
Error err = OS::get_singleton()->open_dynamic_library(abs_path, library, true, &library_path);
if (err != OK) {
ERR_PRINT("GDExtension dynamic library not found: " + abs_path);
return err;
}

#if defined(WINDOWS_ENABLED) && defined(TOOLS_ENABLED)
// If we copied the file, let's change the library path to point at the original,
// because that's what we want to check to see if it's changed.
if (library_copied) {
library_path = library_path.get_base_dir() + "\\" + p_path.get_file();
}
#endif

void *entry_funcptr = nullptr;

err = OS::get_singleton()->get_dynamic_library_symbol_handle(library, p_entry_symbol, entry_funcptr, false);
Expand Down

0 comments on commit b06fe0d

Please sign in to comment.