[Scummvm-cvs-logs] CVS: scummvm/gob scenery.cpp,1.15,1.16 scenery.h,1.4,1.5

Torbjörn Andersson eriktorbjorn at users.sourceforge.net
Mon Apr 25 12:04:05 CEST 2005


Update of /cvsroot/scummvm/scummvm/gob
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12835

Modified Files:
	scenery.cpp scenery.h 
Log Message:
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.)


Index: scenery.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/scenery.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- scenery.cpp	25 Apr 2005 18:53:58 -0000	1.15
+++ scenery.cpp	25 Apr 2005 19:03:12 -0000	1.16
@@ -114,6 +114,7 @@
 
 	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 @@
 			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 @@
 		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 @@
 
 	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 @@
 	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 @@
 			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 @@
 		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 @@
 
 	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);
 

Index: scenery.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gob/scenery.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- scenery.h	11 Apr 2005 23:01:42 -0000	1.4
+++ scenery.h	25 Apr 2005 19:03:13 -0000	1.5
@@ -47,14 +47,6 @@
 	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 @@
 } 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;
 };
 





More information about the Scummvm-git-logs mailing list