From 6bd8c4c3cd657a71519636f97f5fde3f999d092e Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Wed, 4 Jan 2012 21:45:36 +0800 Subject: [PATCH] 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. --- src/save.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/save.c b/src/save.c index 361ba8d6e..4d1d9bc10 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