Fix garbage characters in hardware game names
Store game names and descriptions in persistent LuaGameFactoryData structure instead of local stack variables to prevent dangling pointers. Same fix as emulator version.
This commit is contained in:
@@ -16,6 +16,8 @@ extern "C" {
|
|||||||
// 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;
|
||||||
@@ -131,23 +133,22 @@ int LuaGameLoader::register_all_games(GameLauncher* launcher) {
|
|||||||
char script_path[256];
|
char script_path[256];
|
||||||
snprintf(script_path, sizeof(script_path), "/games/%s", fno.fname);
|
snprintf(script_path, sizeof(script_path), "/games/%s", fno.fname);
|
||||||
|
|
||||||
// Parse metadata
|
|
||||||
char name[64];
|
|
||||||
char description[128];
|
|
||||||
parse_metadata(script_path, name, description);
|
|
||||||
|
|
||||||
printf("LuaGameLoader: Found %s - '%s'\n", fno.fname, 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, sizeof(data->script_path) - 1);
|
strncpy(data->script_path, script_path, 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, data->name, data->description);
|
||||||
|
|
||||||
|
printf("LuaGameLoader: Found %s - '%s'\n", fno.fname, 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