From fad89f9d2db7723f4d62ecc5a7834f15153342bd Mon Sep 17 00:00:00 2001 From: Themaister Date: Wed, 26 Oct 2011 19:51:10 +0200 Subject: [PATCH] More gracious error handling for state tracker. --- gfx/shader_cg.c | 13 +++++-------- gfx/shader_glsl.c | 12 +++++------- gfx/snes_state.c | 18 +++++++++--------- gfx/snes_state.h | 1 + 4 files changed, 20 insertions(+), 24 deletions(-) diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 188f91e811..bd8b32a643 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -490,8 +490,8 @@ static bool load_imports(const char *dir_path, config_file_t *conf) unsigned addr = 0; #ifdef HAVE_PYTHON if (tracker_type != SSNES_STATE_PYTHON) - { #endif + { unsigned input_slot = 0; if (config_get_hex(conf, input_slot_buf, &input_slot)) { @@ -525,11 +525,9 @@ static bool load_imports(const char *dir_path, config_file_t *conf) SSNES_ERR("No address assigned to semantic.\n"); goto error; } -#ifdef HAVE_PYTHON } -#endif - int memtype = 0; + unsigned memtype; switch (ram_type) { case SSNES_STATE_WRAM: @@ -549,10 +547,10 @@ static bool load_imports(const char *dir_path, config_file_t *conf) break; default: - memtype = SNES_MEMORY_WRAM; + memtype = -1u; } - if (addr >= psnes_get_memory_size(memtype)) + if ((memtype != -1u) && (addr >= psnes_get_memory_size(memtype))) { SSNES_ERR("Address out of bounds.\n"); goto error; @@ -581,7 +579,7 @@ static bool load_imports(const char *dir_path, config_file_t *conf) .oam = psnes_get_memory_data(SNES_MEMORY_OAM), .apuram = psnes_get_memory_data(SNES_MEMORY_APURAM), .info = info, - .info_elem = info_cnt + .info_elem = info_cnt, }; #ifdef HAVE_PYTHON @@ -613,7 +611,6 @@ static bool load_imports(const char *dir_path, config_file_t *conf) #endif free(imports); - return true; error: diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index 65bf8d7244..8aee3bf4ac 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -483,13 +483,13 @@ static bool get_import_value(xmlNodePtr ptr) goto error; } - enum snes_ram_type ram_type = SSNES_STATE_WRAM; + enum snes_ram_type ram_type = SSNES_STATE_NONE; uint32_t addr = 0; #ifdef HAVE_PYTHON if (tracker_type != SSNES_STATE_PYTHON) - { #endif + { if (input) { unsigned slot = strtoul((const char*)input, NULL, 0); @@ -517,11 +517,9 @@ static bool get_import_value(xmlNodePtr ptr) SSNES_ERR("No RAM address specificed for import value.\n"); goto error; } -#ifdef HAVE_PYTHON } -#endif - int memtype = 0; + unsigned memtype; switch (ram_type) { case SSNES_STATE_WRAM: @@ -541,10 +539,10 @@ static bool get_import_value(xmlNodePtr ptr) break; default: - memtype = SNES_MEMORY_WRAM; + memtype = -1u; } - if (addr >= psnes_get_memory_size(memtype)) + if ((memtype != -1u) && (addr >= psnes_get_memory_size(memtype))) { SSNES_ERR("Address out of bounds.\n"); goto error; diff --git a/gfx/snes_state.c b/gfx/snes_state.c index 363993f51c..7e8eeb26f0 100644 --- a/gfx/snes_state.c +++ b/gfx/snes_state.c @@ -88,32 +88,32 @@ snes_tracker_t* snes_tracker_init(const struct snes_tracker_info *info) strlcpy(tracker->info[i].id, info->info[i].id, sizeof(tracker->info[i].id)); tracker->info[i].addr = info->info[i].addr; tracker->info[i].type = info->info[i].type; - tracker->info[i].mask = (info->info[i].mask == 0) ? 0xffffffffu : info->info[i].mask; + tracker->info[i].mask = (info->info[i].mask == 0) ? -1u : info->info[i].mask; #ifdef HAVE_PYTHON if (info->info[i].type == SSNES_STATE_PYTHON) tracker->info[i].py = tracker->py; #endif - assert(info->wram && info->vram && info->cgram && - info->oam && info->apuram); + // If we don't have a valid pointer. + static const uint8_t empty = 0; switch (info->info[i].ram_type) { case SSNES_STATE_WRAM: - tracker->info[i].ptr = info->wram; + tracker->info[i].ptr = info->wram ? info->wram : ∅ break; case SSNES_STATE_APURAM: - tracker->info[i].ptr = info->apuram; + tracker->info[i].ptr = info->apuram ? info->apuram : ∅ break; case SSNES_STATE_OAM: - tracker->info[i].ptr = info->oam; + tracker->info[i].ptr = info->oam ? info->oam : ∅ break; case SSNES_STATE_CGRAM: - tracker->info[i].ptr = info->cgram; + tracker->info[i].ptr = info->cgram ? info->cgram : ∅ break; case SSNES_STATE_VRAM: - tracker->info[i].ptr = info->vram; + tracker->info[i].ptr = info->vram ? info->vram : ∅ break; case SSNES_STATE_INPUT_SLOT1: tracker->info[i].input_ptr = &tracker->input_state[0]; @@ -125,7 +125,7 @@ snes_tracker_t* snes_tracker_init(const struct snes_tracker_info *info) break; default: - tracker->info[i].ptr = NULL; + tracker->info[i].ptr = ∅ } } diff --git a/gfx/snes_state.h b/gfx/snes_state.h index a4a2df0282..326d38c27c 100644 --- a/gfx/snes_state.h +++ b/gfx/snes_state.h @@ -39,6 +39,7 @@ enum snes_tracker_type enum snes_ram_type { + SSNES_STATE_NONE, SSNES_STATE_WRAM, SSNES_STATE_APURAM, SSNES_STATE_OAM,