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
This commit is contained in:
@@ -18,6 +18,8 @@ namespace fs = std::filesystem;
|
|||||||
// Structure to hold script path for factory closure
|
// Structure to hold script path for factory closure
|
||||||
struct LuaGameFactoryData {
|
struct LuaGameFactoryData {
|
||||||
char script_path[256];
|
char script_path[256];
|
||||||
|
char name[64];
|
||||||
|
char description[128];
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::vector<LuaGameFactoryData*> factory_data_list;
|
static std::vector<LuaGameFactoryData*> factory_data_list;
|
||||||
@@ -124,23 +126,22 @@ int LuaGameLoader::register_all_games(GameLauncher* launcher) {
|
|||||||
|
|
||||||
std::string script_path = entry.path().string();
|
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)
|
// Create factory data (persistent for game lifetime)
|
||||||
LuaGameFactoryData* data = new LuaGameFactoryData();
|
LuaGameFactoryData* data = new LuaGameFactoryData();
|
||||||
strncpy(data->script_path, script_path.c_str(), sizeof(data->script_path) - 1);
|
strncpy(data->script_path, script_path.c_str(), sizeof(data->script_path) - 1);
|
||||||
data->script_path[sizeof(data->script_path) - 1] = '\0';
|
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);
|
factory_data_list.push_back(data);
|
||||||
|
|
||||||
// Register with launcher - using lambda factory pattern
|
// Register with launcher - using lambda factory pattern
|
||||||
launcher->register_game(
|
launcher->register_game(
|
||||||
name,
|
data->name,
|
||||||
description[0] ? description : "Lua Script",
|
data->description[0] ? data->description : "Lua Script",
|
||||||
[data](uint16_t width, uint16_t height, LowLevelRenderer* renderer,
|
[data](uint16_t width, uint16_t height, LowLevelRenderer* renderer,
|
||||||
LowLevelGUI* gui, InputManager* input_manager) -> Game* {
|
LowLevelGUI* gui, InputManager* input_manager) -> Game* {
|
||||||
return new LuaGame(data->script_path, width, height, renderer, gui, input_manager);
|
return new LuaGame(data->script_path, width, height, renderer, gui, input_manager);
|
||||||
|
|||||||
Reference in New Issue
Block a user