fix SOAP crashes by making sure particle id's are between 0 and NPART. Also cut off .life to between 0 and 65535 when saving
This commit is contained in:
parent
074a2226e1
commit
aa2ec3d162
@ -1879,12 +1879,17 @@ char * GameSave::serialiseOPS(int & dataLength)
|
||||
//Life (optional), 1 to 2 bytes
|
||||
if(particles[i].life)
|
||||
{
|
||||
int life = particles[i].life;
|
||||
if (life > 0xFFFF)
|
||||
life = 0xFFFF;
|
||||
else if (life < 0)
|
||||
life = 0;
|
||||
fieldDesc |= 1 << 1;
|
||||
partsData[partsDataLen++] = particles[i].life;
|
||||
partsData[partsDataLen++] = life;
|
||||
if(particles[i].life & 0xFF00)
|
||||
{
|
||||
fieldDesc |= 1 << 2;
|
||||
partsData[partsDataLen++] = particles[i].life >> 8;
|
||||
partsData[partsDataLen++] = life >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1962,6 +1967,7 @@ char * GameSave::serialiseOPS(int & dataLength)
|
||||
}
|
||||
}
|
||||
|
||||
//Pavg, 4 bytes
|
||||
//Don't save pavg for things that break under pressure, because then they will break when the save is loaded, since pressure isn't also loaded
|
||||
if ((particles[i].pavg[0] || particles[i].pavg[1]) && !(particles[i].type == PT_QRTZ || particles[i].type == PT_GLAS || particles[i].type == PT_TUNG))
|
||||
{
|
||||
@ -1972,7 +1978,7 @@ char * GameSave::serialiseOPS(int & dataLength)
|
||||
partsData[partsDataLen++] = ((int)particles[i].pavg[1])>>8;
|
||||
}
|
||||
|
||||
//Write the field descriptor;
|
||||
//Write the field descriptor
|
||||
partsData[fieldDescLoc] = fieldDesc;
|
||||
partsData[fieldDescLoc+1] = fieldDesc>>8;
|
||||
|
||||
|
@ -161,7 +161,6 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
|
||||
}
|
||||
else if (parts[r>>8].ctype == 7 && parts[i].tmp != r>>8 && parts[i].tmp2 != r>>8)
|
||||
{
|
||||
int buf;
|
||||
parts[parts[i].tmp].tmp2 = parts[r>>8].tmp2;
|
||||
parts[parts[r>>8].tmp2].tmp = parts[i].tmp;
|
||||
parts[r>>8].tmp2 = i;
|
||||
@ -181,17 +180,20 @@ int Element_SOAP::update(UPDATE_FUNC_ARGS)
|
||||
parts[i].vx += dx*d;
|
||||
parts[i].vy += dy*d;
|
||||
if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1)
|
||||
&& (parts[parts[i].tmp].tmp >= 0 && parts[parts[i].tmp].tmp < NPART)
|
||||
&& (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1))
|
||||
{
|
||||
int ii;
|
||||
ii = parts[parts[parts[i].tmp].tmp].tmp;
|
||||
dx = parts[ii].x - parts[parts[i].tmp].x;
|
||||
dy = parts[ii].y - parts[parts[i].tmp].y;
|
||||
d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5;
|
||||
parts[parts[i].tmp].vx -= dx*d*0.5f;
|
||||
parts[parts[i].tmp].vy -= dy*d*0.5f;
|
||||
parts[ii].vx += dx*d*0.5f;
|
||||
parts[ii].vy += dy*d*0.5f;
|
||||
int ii = parts[parts[parts[i].tmp].tmp].tmp;
|
||||
if (ii >= 0 && ii < NPART)
|
||||
{
|
||||
dx = parts[ii].x - parts[parts[i].tmp].x;
|
||||
dy = parts[ii].y - parts[parts[i].tmp].y;
|
||||
d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5;
|
||||
parts[parts[i].tmp].vx -= dx*d*0.5f;
|
||||
parts[parts[i].tmp].vy -= dy*d*0.5f;
|
||||
parts[ii].vx += dx*d*0.5f;
|
||||
parts[ii].vy += dy*d*0.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user