Add safeguard to try_move to ensure we don't write to out of bounds pmap
This is a follow up to this crash fix - 0ed8d0a0be
This may possibly fix other crashes users occasionally experience, especially in the case of high velocity particles with loop edge mode on. Even so, there are other bugs at play, as a crash here can't be triggered if pmap is in a correct state
This commit is contained in:
parent
656ace10c6
commit
982fdff528
@ -2863,9 +2863,14 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
|
|||||||
|
|
||||||
if (ID(pmap[ny][nx]) == ri)
|
if (ID(pmap[ny][nx]) == ri)
|
||||||
pmap[ny][nx] = 0;
|
pmap[ny][nx] = 0;
|
||||||
parts[ri].x += float(x-nx);
|
parts[ri].x += float(x - nx);
|
||||||
parts[ri].y += float(y-ny);
|
parts[ri].y += float(y - ny);
|
||||||
pmap[(int)(parts[ri].y+0.5f)][(int)(parts[ri].x+0.5f)] = PMAP(ri, parts[ri].type);
|
int rx = int(parts[ri].x + 0.5f);
|
||||||
|
int ry = int(parts[ri].y + 0.5f);
|
||||||
|
// This check will never fail unless the pmap array has already been corrupted via another bug
|
||||||
|
// In that case, r's position is inaccurate (not actually at nx/ny) and rx/ry may be out of bounds
|
||||||
|
if (InBounds(rx, ry))
|
||||||
|
pmap[ry][rx] = PMAP(ri, parts[ri].type);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user