summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2012-01-04 13:45:36 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-05 00:46:11 (GMT)
commit6bd8c4c3cd657a71519636f97f5fde3f999d092e (patch)
tree62ef508b03f0ccd473545e5fc9efd280e82a89f0 /src
parent8b88557047ad397aac14c0dd161801501f95d97a (diff)
downloadpowder-6bd8c4c3cd657a71519636f97f5fde3f999d092e.zip
powder-6bd8c4c3cd657a71519636f97f5fde3f999d092e.tar.gz
Fix zero length save crash, ignore sign tool walls, allocate parts starting at beginning of array
Allocating parts starting at end was making saves loaded from OPS files run slower, because no particles could be skipped by using parts_lastActiveIndex.
Diffstat (limited to 'src')
-rw-r--r--src/save.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/save.c b/src/save.c
index 361ba8d..4d1d9bc 100644
--- a/src/save.c
+++ b/src/save.c
@@ -9,6 +9,10 @@
pixel *prerender_save(void *save, int size, int *width, int *height)
{
unsigned char * saveData = save;
+ if (size<16)
+ {
+ return NULL;
+ }
if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
{
return prerender_save_OPS(save, size, width, height);
@@ -31,6 +35,10 @@ void *build_save(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h, un
int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr, unsigned pmap[YRES][XRES])
{
unsigned char * saveData = save;
+ if (size<16)
+ {
+ return 1;
+ }
if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
{
return parse_save_OPS(save, size, replace, x0, y0, bmap, vx, vy, pv, fvx, fvy, signs, partsptr, pmap);
@@ -930,6 +938,7 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c
int newIndex = 0, fieldDescriptor, tempTemp;
int posCount, posTotal, partsPosDataIndex = 0;
int saved_x, saved_y;
+ int freeIndicesIndex = 0;
if(fullW * fullH * 3 > partsPosDataLen)
{
fprintf(stderr, "Not enough particle position data\n");
@@ -982,10 +991,10 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c
//Replace existing particle or allocated block
newIndex = pmap[y][x]>>8;
}
- else if(freeIndicesCount)
+ else if(freeIndicesIndex<freeIndicesCount)
{
//Create new particle
- newIndex = freeIndices[--freeIndicesCount];
+ newIndex = freeIndices[freeIndicesIndex++];
}
else
{
@@ -1611,6 +1620,14 @@ int parse_save_PSv(void *save, int size, int replace, int x0, int y0, unsigned c
{
if (d[p])
{
+ //In old saves, ignore walls created by sign tool bug
+ //Not ignoring other invalid walls or invalid walls in new saves, so that any other bugs causing them are easier to notice, find and fix
+ if (ver<71 && d[p]==WL_SIGN)
+ {
+ p++;
+ continue;
+ }
+
bmap[y][x] = d[p];
if (bmap[y][x]==1)
bmap[y][x]=WL_WALL;