From 114d8e4a366a382240e251df86669d7604824344 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Sat, 7 Jan 2012 17:48:55 +0000 Subject: [PATCH] When defining a model with the 'model' token and there were errors, don't let it hang around causing trouble later on; delete it right now and inform the user. Add a couple of 'static's to some functions and file scope data in mdsprite.c git-svn-id: https://svn.eduke32.com/eduke32@2237 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/defs.c | 27 +++++++++++++++++++++++++++ polymer/eduke32/build/src/mdsprite.c | 10 ++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/polymer/eduke32/build/src/defs.c b/polymer/eduke32/build/src/defs.c index f3637edf3..972911897 100644 --- a/polymer/eduke32/build/src/defs.c +++ b/polymer/eduke32/build/src/defs.c @@ -934,6 +934,8 @@ static int32_t defsparser(scriptfile *script) int32_t shadeoffs=0, pal=0, flags=0; uint8_t usedframebitmap[1024>>3]; + int32_t model_ok = 1; + static const tokenlist modeltokens[] = { { "scale", T_SCALE }, @@ -1020,6 +1022,7 @@ static int32_t defsparser(scriptfile *script) if (ftilenume < 0) initprintf("Error: missing 'first tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; if (ltilenume < 0) initprintf("Error: missing 'last tile number' for frame definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,frametokptr)), happy = 0; + model_ok &= happy; if (!happy) break; if (ltilenume < ftilenume) @@ -1057,6 +1060,8 @@ static int32_t defsparser(scriptfile *script) if (framei >= 0 && framei<1024) usedframebitmap[framei>>3] |= (1<<(framei&7)); } + + model_ok &= happy; } #endif seenframe = 1; @@ -1095,6 +1100,7 @@ static int32_t defsparser(scriptfile *script) if (!startframe) initprintf("Error: missing 'start frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; if (!endframe) initprintf("Error: missing 'end frame' for anim definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)), happy = 0; + model_ok &= happy; if (!happy) break; if (lastmodelid < 0) @@ -1112,14 +1118,17 @@ static int32_t defsparser(scriptfile *script) case -2: initprintf("Invalid starting frame name on line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)); + model_ok = 0; break; case -3: initprintf("Invalid ending frame name on line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)); + model_ok = 0; break; case -4: initprintf("Out of memory on line %s:%d\n", script->filename, scriptfile_getlinum(script,animtokptr)); + model_ok = 0; break; } #endif @@ -1168,6 +1177,7 @@ static int32_t defsparser(scriptfile *script) if (!skinfn) { initprintf("Error: missing 'skin filename' for skin definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); + model_ok = 0; break; } @@ -1201,14 +1211,17 @@ static int32_t defsparser(scriptfile *script) case -2: initprintf("Invalid skin filename on line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); + model_ok = 0; break; case -3: initprintf("Invalid palette number on line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); + model_ok = 0; break; case -4: initprintf("Out of memory on line %s:%d\n", script->filename, scriptfile_getlinum(script,skintokptr)); + model_ok = 0; break; } #endif @@ -1271,6 +1284,7 @@ static int32_t defsparser(scriptfile *script) if (ftilenume < 0) initprintf("Error: missing 'first tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; if (ltilenume < 0) initprintf("Error: missing 'last tile number' for hud definition near line %s:%d\n", script->filename, scriptfile_getlinum(script,hudtokptr)), happy = 0; + model_ok &= happy; if (!happy) break; if (ltilenume < ftilenume) @@ -1306,6 +1320,8 @@ static int32_t defsparser(scriptfile *script) happy = 0; break; } + + model_ok &= happy; } #endif } @@ -1313,6 +1329,17 @@ static int32_t defsparser(scriptfile *script) } } + if (!model_ok) + { + if (lastmodelid >= 0) + { + initprintf("Removing model %d due to errors.\n", lastmodelid); + md_undefinemodel(lastmodelid); + nextmodelid--; + } + break; + } + #ifdef USE_OPENGL md_setmisc(lastmodelid,(float)scale,shadeoffs,(float)mzadd,flags); diff --git a/polymer/eduke32/build/src/mdsprite.c b/polymer/eduke32/build/src/mdsprite.c index 9ee5269aa..641aaaa5a 100644 --- a/polymer/eduke32/build/src/mdsprite.c +++ b/polymer/eduke32/build/src/mdsprite.c @@ -34,7 +34,7 @@ static void QuitOnFatalError(const char *msg) } -int32_t addtileP(int32_t model,int32_t tile,int32_t pallet) +static int32_t addtileP(int32_t model,int32_t tile,int32_t pallet) { UNREFERENCED_PARAMETER(model); if (curextra==MAXTILES+EXTRATILES-2)return curextra; @@ -75,7 +75,7 @@ static GLuint *indexvbos = NULL; mdmodel_t *mdload(const char *); int32_t mddraw(spritetype *); -void mdfree(mdmodel_t *); +static void mdfree(mdmodel_t *); int32_t globalnoeffect=0; extern int32_t timerticspersec; @@ -501,6 +501,8 @@ int32_t md_undefinetile(int32_t tile) return 0; } +/* this function is problematic, it leaves NULL holes in model[] + * (which runs from 0 to nextmodelid-1) */ int32_t md_undefinemodel(int32_t modelid) { int32_t i; @@ -520,8 +522,8 @@ int32_t md_undefinemodel(int32_t modelid) return 0; } -md2model_t *modelhead; -mdskinmap_t *skhead; +static md2model_t *modelhead; +static mdskinmap_t *skhead; static int32_t daskinloader(int32_t filh, intptr_t *fptr, int32_t *bpl, int32_t *sizx, int32_t *sizy, int32_t *osizx, int32_t *osizy, char *hasalpha, int32_t pal, char effect) {