From f7154d8c78eb76dc87885eacd5a7875c73b20a67 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 19 Apr 2010 21:22:26 +0000 Subject: [PATCH] Various mapster32 fixes: check wall limits in sector drawing; don't count BACKSPACEing there as a new revision (probably fixes undo-related crashes). Also a patch-fix for a crash I couldn't pin down exactly and a corruption checker for m32script. git-svn-id: https://svn.eduke32.com/eduke32@1622 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/a.m32 | 79 +++++++++++++++++++++ polymer/eduke32/build/src/build.c | 113 +++++++++++++++++++----------- 2 files changed, 153 insertions(+), 39 deletions(-) diff --git a/polymer/eduke32/a.m32 b/polymer/eduke32/a.m32 index 60a397a5d..a5f259766 100644 --- a/polymer/eduke32/a.m32 +++ b/polymer/eduke32/a.m32 @@ -517,3 +517,82 @@ defstate resetallws // reset all sprites and walls to default repeat/panning fixrepeats i } ends + +defstate jumptosec // (tmp) + for i allsectors + { + ife i tmp + { + set j sector[i].wallptr + set posx wall[j].x + set posy wall[j].y + } + } +ends + +// Map corruption checker +definequote 19 PANIC!!! SECTOR OR WALL LIMIT EXCEEDED!!! +definequote 20 SECTOR[%d].WALLPTR=%d out of range: numwalls=%d!!! +definequote 21 SECTOR[%d].WALLPTR=%d inconsistent, expected %d!!! +definequote 22 SECTOR[%d]: wallptr+wallnum=%d out of range: numwalls=%d!!! +definequote 23 WALL[%d].POINT2=%d out of range: sector[%d].wallptr=%d, endwall=%d!!! +definequote 24 WALL[%d].NEXTWALL=%d out of range: numwalls=%d!!! +definequote 25 WALL[%d].NEXTSECTOR=%d out of range: numsectors=%d!!! + +gamevar ewall 0 0 +gamevar endwall 0 0 + +defstate corruptchk + ifle numsectors MAXSECTORS ifle numwalls MAXWALLS nullop else + { quote 19 printmessage16 19 return } + set ewall 0 // expected wall index + for i allsectors + { + set k 1 + ifge sector[i].wallptr 0 ifl sector[i].wallptr numwalls nullop else + { + qsprintf TQUOTE 20 i sector[i].wallptr numwalls + quote TQUOTE printmessage16 TQUOTE + set k 0 + } + ifn ewall sector[i].wallptr + { + qsprintf TQUOTE 21 i sector[i].wallptr ewall + quote TQUOTE printmessage16 TQUOTE + set ewall sector[i].wallptr + } + add ewall sector[i].wallnum + + set endwall sector[i].wallptr add endwall sector[i].wallnum + ifg endwall numwalls + { + qsprintf TQUOTE 22 i endwall numwalls + quote TQUOTE printmessage16 TQUOTE + set k 0 + } + + ifn k 0 + { + for j wallsofsector i + { + ifge wall[j].point2 sector[i].wallptr ifl wall[i].point2 endwall nullop else + { + qsprintf TQUOTE 23 j wall[j].point2 i sector[i].wallptr endwall + quote TQUOTE printmessage16 TQUOTE + } + + ifge wall[i].nextwall numwalls + { + qsprintf TQUOTE 24 j wall[j].nextwall numwalls + quote TQUOTE printmessage16 TQUOTE + } + + ifge wall[i].nextsector numsectors + { + qsprintf TQUOTE 25 j wall[j].nextsector numsectors + quote TQUOTE printmessage16 TQUOTE + } + } + } + } +ends diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index 999fb60b8..385f9d839 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -1194,6 +1194,8 @@ char changechar(char dachar, int32_t dadir, char smooshyalign, char boundcheck) return(dachar); } +static int32_t newnumwalls=-1; + void overheadeditor(void) { char buffer[80], *dabuffer, ch; @@ -1201,7 +1203,7 @@ void overheadeditor(void) int32_t tempint, tempint1, tempint2, doubvel; int32_t startwall=0, endwall, dax, day, x1, y1, x2, y2, x3, y3, x4, y4; int32_t highlightx1, highlighty1, highlightx2, highlighty2, xvect, yvect; - int16_t pag, suckwall=0, sucksect, newnumwalls, newnumsectors, split=0, bad; + int16_t pag, suckwall=0, sucksect, /*newnumwalls,*/ newnumsectors, split=0, bad; int16_t splitsect=0, danumwalls, secondstartwall, joinsector[2], joinsectnum; int16_t splitstartwall=0, splitendwall, loopnum; int32_t mousx, mousy, bstatus; @@ -3348,9 +3350,16 @@ SKIP: } } - if (bad > 0) //Space + if (bad > 0 && (max(numwalls,newnumwalls) > MAXWALLS - (newnumwalls < numwalls))) { - if ((newnumwalls < numwalls) && (numwalls < MAXWALLS-1)) + if (newnumwalls < numwalls) + printmessage16("Can't start sector drawing: wall limit reached."); + else + printmessage16("Inserting another point would exceed wall limit."); + } + else if (bad > 0) //Space + { + if ((newnumwalls < numwalls) /*&& (numwalls < MAXWALLS-1)*/) { firstx = mousxplc, firsty = mousyplc; //Make first point newnumwalls = numwalls; @@ -3581,6 +3590,7 @@ SKIP: //split sector startwall = sector[splitsect].wallptr; endwall = startwall + sector[splitsect].wallnum - 1; +// OSD_Printf("numwalls: %d, newnumwalls: %d\n", numwalls, newnumwalls); for (k=startwall; k<=endwall; k++) if (wall[k].x == wall[newnumwalls-1].x) if (wall[k].y == wall[newnumwalls-1].y) @@ -3589,6 +3599,16 @@ SKIP: if (loopnumofsector(splitsect,splitstartwall) != loopnumofsector(splitsect,(int16_t)k)) bad = 1; + if (numwalls+2*(newnumwalls-numwalls-1) > MAXWALLS) + { + if (bad==0) + printmessage16("Splitting sector would exceed wall limit."); + else + printmessage16("Joining sector loops would exceed wall limit."); + newnumwalls--; + break; + } + if (bad == 0) { //SPLIT IT! @@ -3954,13 +3974,13 @@ SKIP: if (newnumwalls > numwalls) { newnumwalls--; - asksave = 1; +// asksave = 1; keystatus[0x0e] = 0; } if (newnumwalls == numwalls) { newnumwalls = -1; - asksave = 1; +// asksave = 1; keystatus[0x0e] = 0; } } @@ -4105,6 +4125,7 @@ SKIP: else if (linehighlight >= 0) { int32_t wallsdrawn = newnumwalls-numwalls; + int32_t wallis2sided = (wall[linehighlight].nextwall>=0); if (newnumwalls != -1) { @@ -4113,44 +4134,49 @@ SKIP: } else wallsdrawn = -1; - getclosestpointonwall(mousxplc,mousyplc,(int32_t)linehighlight,&dax,&day); - adjustmark(&dax,&day,newnumwalls); - insertpoint(linehighlight,dax,day); - printmessage16("Point inserted."); - - j = 0; - //Check to see if point was inserted over another point - for (i=numwalls-1; i>=0; i--) //delete points - if (wall[i].x == wall[wall[i].point2].x) - if (wall[i].y == wall[wall[i].point2].y) - { - deletepoint((int16_t)i); - j++; - } - for (i=0; i= MAXWALLS-wallis2sided) + printmessage16("Inserting point would exceed wall limit."); + else { - if ((wall[i].x == dax) && (wall[i].y == day)) + getclosestpointonwall(mousxplc,mousyplc,(int32_t)linehighlight,&dax,&day); + adjustmark(&dax,&day,newnumwalls); + insertpoint(linehighlight,dax,day); + printmessage16("Point inserted."); + + j = 0; + //Check to see if point was inserted over another point + for (i=numwalls-1; i>=0; i--) //delete points + if (wall[i].x == wall[wall[i].point2].x) + if (wall[i].y == wall[wall[i].point2].y) + { + deletepoint((int16_t)i); + j++; + } + for (i=0; i>1); + // day = ((wall[linehighlight].y + wall[wall[linehighlight].point2].y)>>1); + // if ((dax != wall[linehighlight].x) || (day != wall[linehighlight].y)) + // if ((dax != wall[wall[linehighlight].point2].x) || (day != wall[wall[linehighlight].point2].y)) + // { + // insertpoint(linehighlight,dax,day); + // printmessage16("Point inserted at midpoint."); + // } + //} } - //if (j != 0) - //{ - // dax = ((wall[linehighlight].x + wall[wall[linehighlight].point2].x)>>1); - // day = ((wall[linehighlight].y + wall[wall[linehighlight].point2].y)>>1); - // if ((dax != wall[linehighlight].x) || (day != wall[linehighlight].y)) - // if ((dax != wall[wall[linehighlight].point2].x) || (day != wall[wall[linehighlight].point2].y)) - // { - // insertpoint(linehighlight,dax,day); - // printmessage16("Point inserted at midpoint."); - // } - //} if (wallsdrawn != -1) { @@ -5126,6 +5152,15 @@ int32_t checksectorpointer(int16_t i, int16_t sectnum) { int32_t j, k, startwall, endwall, x1, y1, x2, y2; + char buf[128]; + if (i<0 || i>=max(numwalls,newnumwalls)) + { + Bsprintf(buf, "WARN: checksectorpointer called with i=%d but (new)numwalls=%d", i, max(numwalls,newnumwalls)); + OSD_Printf("%s\n", buf); + printmessage16(buf); + return 0; + } + x1 = wall[i].x; y1 = wall[i].y; x2 = wall[wall[i].point2].x;