diff options
author | Torbjörn Andersson | 2005-04-25 19:03:13 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2005-04-25 19:03:13 +0000 |
commit | 21ea71a7620bd2c29f49a940500e0de54c575dfa (patch) | |
tree | c89f10ed9741deb4c8a5cb01e48a991f2b0d03f2 | |
parent | f08a767aa8b5c822f47b3931d7e8c71468112c94 (diff) | |
download | scummvm-rg350-21ea71a7620bd2c29f49a940500e0de54c575dfa.tar.gz scummvm-rg350-21ea71a7620bd2c29f49a940500e0de54c575dfa.tar.bz2 scummvm-rg350-21ea71a7620bd2c29f49a940500e0de54c575dfa.zip |
Keep track per piece whether or not it was dynamically allocated, otherwise
we'll end up trying to free invalid pointers. (Happened to me at the end of
the level where you get the voodoo doll.)
svn-id: r17802
-rw-r--r-- | gob/scenery.cpp | 12 | ||||
-rw-r--r-- | gob/scenery.h | 18 |
2 files changed, 19 insertions, 11 deletions
diff --git a/gob/scenery.cpp b/gob/scenery.cpp index 5b43630670..f592b5ab21 100644 --- a/gob/scenery.cpp +++ b/gob/scenery.cpp @@ -114,6 +114,7 @@ int16 scen_loadStatic(char search) { ptr->layers = (Scen_StaticLayer **)malloc(sizeof(Scen_StaticLayer *) * ptr->layersCount); ptr->pieces = (Scen_PieceDesc **)malloc(sizeof(Scen_PieceDesc *) * picsCount); + ptr->piecesFromExt = (char *)malloc(picsCount); for (i = 0; i < ptr->layersCount; i++) { offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]); @@ -136,10 +137,12 @@ int16 scen_loadStatic(char search) { ptr->pieces[i] = (Scen_PieceDesc *) game_loadExtData(pictDescId, 0, 0); + ptr->piecesFromExt[i] = 1; } else { ptr->pieces[i] = (Scen_PieceDesc *) game_loadTotResource(pictDescId); + ptr->piecesFromExt[i] = 0; } width = inter_load16(); @@ -188,7 +191,7 @@ void scen_freeStatic(int16 index) { return; for (i = 0; i < scen_staticPictCount[index]; i++) { - if (scen_staticFromExt[index] == 1) + if (scen_statics[index].piecesFromExt[i] == 1) free(scen_statics[index].pieces[i]); spr = scen_staticPictToSprite[index * 7 + i]; @@ -202,6 +205,7 @@ void scen_freeStatic(int16 index) { free(scen_statics[index].layers); free(scen_statics[index].pieces); + free(scen_statics[index].piecesFromExt); if (scen_staticFromExt[index] == 1) free(scen_statics[index].dataPtr); @@ -430,6 +434,7 @@ int16 scen_loadAnim(char search) { ptr->pieces = (Scen_PieceDesc **) malloc(sizeof(Scen_PieceDesc *) * picsCount); + ptr->piecesFromExt = (char *) malloc(picsCount); for (i = 0; i < ptr->layersCount; i++) { offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]); @@ -449,10 +454,12 @@ int16 scen_loadAnim(char search) { ptr->pieces[i] = (Scen_PieceDesc *) game_loadExtData(pictDescId, 0, 0); + ptr->piecesFromExt[i] = 1; } else { ptr->pieces[i] = (Scen_PieceDesc *) game_loadTotResource(pictDescId); + ptr->piecesFromExt[i] = 0; } width = inter_load16(); @@ -705,7 +712,7 @@ void scen_freeAnim(int16 animation) { return; for (i = 0; i < scen_animPictCount[animation]; i++) { - if (scen_animFromExt[animation] == 1) + if (scen_animations[animation].piecesFromExt[i] == 1) free(scen_animations[animation].pieces[i]); spr = scen_animPictToSprite[animation * 7 + i]; @@ -720,6 +727,7 @@ void scen_freeAnim(int16 animation) { free(scen_animations[animation].layers); free(scen_animations[animation].pieces); + free(scen_animations[animation].piecesFromExt); if (scen_animFromExt[animation] == 1) free(scen_animations[animation].dataPtr); diff --git a/gob/scenery.h b/gob/scenery.h index 90b098ea14..71b59e685c 100644 --- a/gob/scenery.h +++ b/gob/scenery.h @@ -47,14 +47,6 @@ typedef struct Scen_StaticLayer { Scen_StaticPlane planes[1]; } GCC_PACK Scen_StaticLayer; -typedef struct Scen_Static { - int16 layersCount; - Scen_StaticLayer **layers; - Scen_PieceDesc **pieces; - void *unknown; - char *dataPtr; -} GCC_PACK Scen_Static; - // Animations typedef struct Scen_AnimFramePiece { @@ -77,11 +69,19 @@ typedef struct Scen_AnimLayer { } GCC_PACK Scen_AnimLayer; #pragma END_PACK_STRUCTS +typedef struct Scen_Static { + int16 layersCount; + Scen_StaticLayer **layers; + Scen_PieceDesc **pieces; + char *piecesFromExt; + char *dataPtr; +} Scen_Static; + struct Scen_Animation { int16 layersCount; Scen_AnimLayer **layers; Scen_PieceDesc **pieces; - void *unknowm; + char *piecesFromExt; char *dataPtr; }; |