diff --git a/addons/libLibRetroHost-d.so b/addons/libLibRetroHost-d.so index cf226e8..65858b7 100755 Binary files a/addons/libLibRetroHost-d.so and b/addons/libLibRetroHost-d.so differ diff --git a/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.internal b/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.internal index 5989cbf..1520111 100644 --- a/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.internal +++ b/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.internal @@ -1718,6 +1718,7 @@ CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/signal.hpp /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/string.hpp /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/string_name.hpp + /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/utility_functions.hpp /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/variant_size.hpp /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/include/godot_cpp/classes/ref.hpp /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/include/godot_cpp/classes/wrapped.hpp diff --git a/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.make b/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.make index 5fee7cc..aad7ca0 100644 --- a/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.make +++ b/gdlibretro/CMakeFiles/LibRetroHost.dir/compiler_depend.make @@ -1713,6 +1713,7 @@ CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o: src/RegisterExtension.c extern/godot-cpp/gen/include/godot_cpp/variant/signal.hpp \ extern/godot-cpp/gen/include/godot_cpp/variant/string.hpp \ extern/godot-cpp/gen/include/godot_cpp/variant/string_name.hpp \ + extern/godot-cpp/gen/include/godot_cpp/variant/utility_functions.hpp \ extern/godot-cpp/gen/include/godot_cpp/variant/variant_size.hpp \ extern/godot-cpp/include/godot_cpp/classes/ref.hpp \ extern/godot-cpp/include/godot_cpp/classes/wrapped.hpp \ diff --git a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/CoreEnvironment.cpp.o b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/CoreEnvironment.cpp.o index 146fcfa..c5d6136 100644 Binary files a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/CoreEnvironment.cpp.o and b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/CoreEnvironment.cpp.o differ diff --git a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o index 337b388..d9eed2a 100644 Binary files a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o and b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o differ diff --git a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o.d b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o.d index 9813ac6..a623b70 100644 --- a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o.d +++ b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o.d @@ -264,6 +264,7 @@ CMakeFiles/LibRetroHost.dir/src/RegisterExtension.cpp.o: \ /usr/include/c++/14/bits/hashtable_policy.h \ /usr/include/c++/14/bits/enable_special_members.h \ /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/classes/engine.hpp \ + /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/extern/godot-cpp/gen/include/godot_cpp/variant/utility_functions.hpp \ /home/jay/gits/RetroQUEST/RetroQUEST/gdlibretro/src/RetroHost.hpp \ /usr/include/c++/14/filesystem /usr/include/c++/14/bits/fs_fwd.h \ /usr/include/c++/14/bits/chrono.h /usr/include/c++/14/ratio \ diff --git a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RetroHost.cpp.o b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RetroHost.cpp.o index c78a553..757088e 100644 Binary files a/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RetroHost.cpp.o and b/gdlibretro/CMakeFiles/LibRetroHost.dir/src/RetroHost.cpp.o differ diff --git a/gdlibretro/CMakeFiles/Makefile.cmake b/gdlibretro/CMakeFiles/Makefile.cmake index fdb0404..0e83aff 100644 --- a/gdlibretro/CMakeFiles/Makefile.cmake +++ b/gdlibretro/CMakeFiles/Makefile.cmake @@ -7,18 +7,14 @@ set(CMAKE_DEPENDS_GENERATOR "Unix Makefiles") # The top level Makefile was generated from the following files: set(CMAKE_MAKEFILE_DEPENDS "CMakeCache.txt" - ".git/HEAD" - ".git/refs/heads/master" "CMakeFiles/3.30.3/CMakeCXXCompiler.cmake" "CMakeFiles/3.30.3/CMakeSystem.cmake" "CMakeFiles/VerifyGlobs.cmake" "CMakeFiles/cmake.verify_globs" - "CMakeFiles/git-data/grabRef.cmake" "CMakeLists.txt" "cmake/ClangFormat.cmake" "cmake/CompilerWarnings.cmake" "cmake/GetGitRevisionDescription.cmake" - "cmake/GetGitRevisionDescription.cmake.in" "cmake/GitVersionInfo.cmake" "cmake/ccache.cmake" "extern/CMakeLists.txt" @@ -77,12 +73,6 @@ set(CMAKE_MAKEFILE_OUTPUTS # Byproducts of CMake generate step: set(CMAKE_MAKEFILE_PRODUCTS - "CMakeFiles/git-data/HEAD" - "CMakeFiles/git-data/grabRef.cmake" - "CMakeFiles/git-data/head-ref" - "CMakeFiles/git-data/HEAD" - "CMakeFiles/git-data/grabRef.cmake" - "CMakeFiles/git-data/head-ref" "gen/Version.h" "CMakeFiles/CMakeDirectoryInformation.cmake" "src/CMakeFiles/CMakeDirectoryInformation.cmake" diff --git a/gdlibretro/gen/Version.h b/gdlibretro/gen/Version.h index aa3f087..f7d33f2 100644 --- a/gdlibretro/gen/Version.h +++ b/gdlibretro/gen/Version.h @@ -30,16 +30,16 @@ namespace VersionInfo { // // It uses the form " -<# commits since last tag>-". // If there are no commits since the last tag, only the tag is shown. - constexpr std::string_view VERSION_STR = "LibRetroHost 7ebbf84"; + constexpr std::string_view VERSION_STR = "LibRetroHost HEAD-HASH-NOTFOUND"; // The version information as a string. // This is generated using the current git commit information. // // It uses the form "-<# commits since last tag>-". // If there are no commits since the last tag, only the tag is shown. - constexpr std::string_view VERSION_SHORT_STR = "7ebbf84"; + constexpr std::string_view VERSION_SHORT_STR = "HEAD-HASH-NOTFOUND"; // The full git SHA1 hash as a string. // This is generated using the current git commit information. - constexpr std::string_view GIT_SHA1_STR = "7ebbf840187f54466988c0b5b20524ad21ca1d58"; + constexpr std::string_view GIT_SHA1_STR = "GITDIR-NOTFOUND"; } diff --git a/gdlibretro/src/RegisterExtension.cpp b/gdlibretro/src/RegisterExtension.cpp index 49cab27..3fdb8be 100644 --- a/gdlibretro/src/RegisterExtension.cpp +++ b/gdlibretro/src/RegisterExtension.cpp @@ -4,7 +4,7 @@ #include "godot_cpp/core/defs.hpp" #include "godot_cpp/godot.hpp" #include "godot_cpp/classes/engine.hpp" -//#include "godot_cpp/variant/utility_functions.hpp" +#include "godot_cpp/variant/utility_functions.hpp" #include "RetroHost.hpp" @@ -18,8 +18,15 @@ namespace { godot::ClassDB::register_class(); + godot::UtilityFunctions::print("[RetroHost] Initializing extension..."); retro_host_singleton = memnew(RetroHost()); + if (!retro_host_singleton) { + godot::UtilityFunctions::printerr("[RetroHost] Failed to allocate memory for singleton."); + return; + } godot::Engine::get_singleton()->register_singleton("RetroHost", RetroHost::get_singleton()); + godot::UtilityFunctions::print("[RetroHost] Singleton registered successfully."); + } void uninitialize_extension(godot::ModuleInitializationLevel p_level) { @@ -37,12 +44,14 @@ extern "C" { GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) { //godot::UtilityFunctions::print("[LibRetroHost] GDExtensionInit called"); + godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization); init_obj.register_initializer(initialize_extension); init_obj.register_terminator(uninitialize_extension); init_obj.set_minimum_library_initialization_level(godot::MODULE_INITIALIZATION_LEVEL_SCENE); + //godot::UtilityFunctions::print("[LibRetroHost] Initialization setup completed."); return init_obj.init(); } } diff --git a/gdlibretro/src/RetroHost.cpp b/gdlibretro/src/RetroHost.cpp index 80f3523..5874c88 100644 --- a/gdlibretro/src/RetroHost.cpp +++ b/gdlibretro/src/RetroHost.cpp @@ -102,6 +102,7 @@ bool RetroHost::load_core(godot::String name) { #elif defined(PLATFORM_LINUX) || defined(PLATFORM_ANDROID) this->core.handle = dlopen(lib_path.utf8().get_data(), RTLD_LAZY); if (this->core.handle == nullptr) { + godot::UtilityFunctions::printerr("[RetroHost] dlopen failed: ", dlerror()); godot::UtilityFunctions::printerr("[RetroHost] Failed to load core \"", lib_path, "\". Error: ", GetLastErrorAsStr().c_str()); return false; } diff --git a/main.gd b/main.gd index 21b2def..a73ea28 100644 --- a/main.gd +++ b/main.gd @@ -3,25 +3,30 @@ extends Node @onready var loader = preload("res://scripts/libretro_loader.gd").new() func _ready(): + print("[main] Entering _ready function") var core_path = "res://cores/genesis_plus_gx_libretro.so" # Replace with your actual core path if not FileAccess.file_exists(core_path): push_error("Core not found at: " + core_path) - return false + return false + else: + print("[main] File ", core_path," exists") var rom_path = "res://roms/megadrive/Sonic the Hedgehog.bin" # Replace with your actual ROM path if not FileAccess.file_exists(rom_path): - push_error("Rom not found at: " + rom_path) - return false + push_error("[main] Rom not found at: " + rom_path) + return false + else: + print("[main] File ", rom_path," exists") - print("Core path: ", core_path) - print("ROM path: ", rom_path) + print("[main] Core path: ", core_path) + print("[main] ROM path: ", rom_path) var success = await loader.start_emulation(core_path, rom_path) # Use await to call the coroutine if success: - print("Game started successfully.") + print("[main] Game started successfully.") start_emulation_loop() else: - print("Failed to start the game.") + print("[main] Failed to start the game.") func start_emulation_loop(): """ diff --git a/prompt.sh b/prompt.sh index ab777f3..301ccb8 100755 --- a/prompt.sh +++ b/prompt.sh @@ -33,10 +33,16 @@ done write "" write "My issue now is the following, can you help me to fix it?" write ' -I enter in the scene but the emulated game is not loaded, I just get this log: -[RetroHost] Constructor - -Maybe we should enhance the logging to understand what is actually happening -' +When I load godot I get this crash: + godot . +================================================================ +handle_crash: Program crashed with signal 11 +Engine version: Godot Engine v4.2.2.rc2.mono.official (c61a68614e5b030a4a1e11abaa5a893b8017f78d) +Dumping the backtrace. Please include this when reporting the bug to the project developer. +[1] /lib/x86_64-linux-gnu/libc.so.6(+0x45250) [0x7ea94c445250] (??:0) +-- END OF BACKTRACE -- +================================================================ +Annullato (core dump creato) +' \ No newline at end of file diff --git a/scripts/libretro_loader.gd b/scripts/libretro_loader.gd index 9cda357..3c7e3d2 100644 --- a/scripts/libretro_loader.gd +++ b/scripts/libretro_loader.gd @@ -2,13 +2,19 @@ extends Node @onready var sub_viewport = $room/SubViewport @onready var texture_rect = $room/SubViewport/TextureRect +@onready var retro_host = Engine.get_singleton("RetroHost") # Get the RetroHost singleton var current_core : Object = null # The emulator core (passed dynamically) var current_rom : String = "" # Initialize to an empty string func start_emulation(core_path: String, rom_path: String) -> bool: print("[libretro_loader] Starting emulation with core: ", core_path, ", ROM: ", rom_path) - + + # Check if RetroHost is available + if not retro_host: + push_error("[libretro_loader] RetroHost singleton not found!") + return false + if not core_path: push_error("[libretro_loader] Core path is missing.") return false @@ -17,35 +23,34 @@ func start_emulation(core_path: String, rom_path: String) -> bool: push_error("[libretro_loader] ROM path is missing.") return false - # Load the core (emulator) - print("[libretro_loader] Loading core...") - current_core = load(core_path) - if not current_core: + # Load the core (via RetroHost) + print("[libretro_loader] Loading core using RetroHost...") + var core_loaded = retro_host.load_core(core_path) + if not core_loaded: push_error("[libretro_loader] Failed to load core: " + core_path) return false + print("[libretro_loader] Core loaded successfully.") - current_core.initialize() - print("[libretro_loader] Core initialized.") - - # Load the ROM - print("[libretro_loader] Checking ROM file...") + # Check if ROM file exists if not FileAccess.file_exists(rom_path): push_error("[libretro_loader] ROM not found: " + rom_path) return false print("[libretro_loader] ROM file exists.") + # Load the ROM + print("[libretro_loader] Opening ROM...") var file = FileAccess.open(rom_path, FileAccess.READ) if not file: - push_error("Error opening ROM: " + rom_path) + push_error("[libretro_loader] Failed to open ROM: " + rom_path) return false - print("ROM file opened successfully.") var rom_data = file.get_buffer(file.get_length()) file.close() print("[libretro_loader] ROM data loaded successfully.") - if not current_core.load_game(rom_data): - push_error("[libretro_loader] Failed to load ROM: " + rom_path) + # Pass ROM data to the core + if not retro_host.core.load_game(rom_data): + push_error("[libretro_loader] Failed to load ROM into core: " + rom_path) return false print("[libretro_loader] ROM loaded successfully.") @@ -99,10 +104,23 @@ func _ready(): """ print("[libretro_loader] _ready: Initializing SubViewport and TextureRect.") if sub_viewport and texture_rect: - print("SubViewport and TextureRect initialized successfully.") + print("[libretro_loader] SubViewport and TextureRect initialized successfully.") else: push_error("Error: SubViewport or TextureRect is missing.") + return + + if not retro_host: + push_error("[libretro_loader] RetroHost singleton not found! Emulation cannot proceed.") + return + print("[libretro_loader] RetroHost singleton initialized successfully.") # Ensure SubViewport always renders sub_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS print("[libretro_loader] SubViewport set to always update.") + + # Use await to call the coroutine + var success = await start_emulation("res://cores/genesis_plus_gx_libretro.so", "res://roms/megadrive/Sonic") + if success: + print("[libretro_loader] Emulation started successfully.") + else: + print("[libretro_loader] Failed to start emulation.")