From 22f5f1f5b285c41bc901196a269f26ab9f237e9f Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Sat, 7 Feb 2026 13:08:22 -0500 Subject: [PATCH] Fix garbage characters in emulator game names Store game names and descriptions in persistent LuaGameFactoryData structure instead of local stack variables to prevent dangling pointers --- emulator/lua_game_loader_emulator.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/emulator/lua_game_loader_emulator.cpp b/emulator/lua_game_loader_emulator.cpp index 78f8017..5ae381b 100644 --- a/emulator/lua_game_loader_emulator.cpp +++ b/emulator/lua_game_loader_emulator.cpp @@ -18,6 +18,8 @@ namespace fs = std::filesystem; // Structure to hold script path for factory closure struct LuaGameFactoryData { char script_path[256]; + char name[64]; + char description[128]; }; static std::vector factory_data_list; @@ -124,23 +126,22 @@ int LuaGameLoader::register_all_games(GameLauncher* launcher) { std::string script_path = entry.path().string(); - // Parse metadata - char name[64]; - char description[128]; - parse_metadata(script_path.c_str(), name, description); - - printf("LuaGameLoader: Found %s - '%s'\n", entry.path().filename().string().c_str(), name); - // Create factory data (persistent for game lifetime) LuaGameFactoryData* data = new LuaGameFactoryData(); strncpy(data->script_path, script_path.c_str(), sizeof(data->script_path) - 1); data->script_path[sizeof(data->script_path) - 1] = '\0'; + + // Parse metadata directly into persistent storage + parse_metadata(script_path.c_str(), data->name, data->description); + + printf("LuaGameLoader: Found %s - '%s'\n", entry.path().filename().string().c_str(), data->name); + factory_data_list.push_back(data); // Register with launcher - using lambda factory pattern launcher->register_game( - name, - description[0] ? description : "Lua Script", + data->name, + data->description[0] ? data->description : "Lua Script", [data](uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager) -> Game* { return new LuaGame(data->script_path, width, height, renderer, gui, input_manager);