Fix crash with smudge tool around the edges
This commit is contained in:
parent
aea8402383
commit
d901b2f8ef
@ -783,31 +783,34 @@ void Simulation::ApplyDecoration(int x, int y, int colR_, int colG_, int colB_,
|
||||
}
|
||||
else if (mode == DECO_SMUDGE)
|
||||
{
|
||||
float tas = 0.0f, trs = 0.0f, tgs = 0.0f, tbs = 0.0f;
|
||||
|
||||
int rx, ry;
|
||||
float num = 0;
|
||||
for (rx=-2; rx<3; rx++)
|
||||
for (ry=-2; ry<3; ry++)
|
||||
{
|
||||
if (abs(rx)+abs(ry) > 2 && (pmap[y+ry][x+rx]&0xFF) && parts[pmap[y+ry][x+rx]>>8].dcolour)
|
||||
if (x >= CELL && x < XRES-CELL && y >= CELL && y < YRES-CELL)
|
||||
{
|
||||
float tas = 0.0f, trs = 0.0f, tgs = 0.0f, tbs = 0.0f;
|
||||
|
||||
int rx, ry;
|
||||
float num = 0;
|
||||
for (rx=-2; rx<3; rx++)
|
||||
for (ry=-2; ry<3; ry++)
|
||||
{
|
||||
Particle part = parts[pmap[y+ry][x+rx]>>8];
|
||||
num += 1.0f;
|
||||
tas += ((float)((part.dcolour>>24)&0xFF));
|
||||
trs += ((float)((part.dcolour>>16)&0xFF));
|
||||
tgs += ((float)((part.dcolour>>8)&0xFF));
|
||||
tbs += ((float)((part.dcolour)&0xFF));
|
||||
if (abs(rx)+abs(ry) > 2 && (pmap[y+ry][x+rx]&0xFF) && parts[pmap[y+ry][x+rx]>>8].dcolour)
|
||||
{
|
||||
Particle part = parts[pmap[y+ry][x+rx]>>8];
|
||||
num += 1.0f;
|
||||
tas += ((float)((part.dcolour>>24)&0xFF));
|
||||
trs += ((float)((part.dcolour>>16)&0xFF));
|
||||
tgs += ((float)((part.dcolour>>8)&0xFF));
|
||||
tbs += ((float)((part.dcolour)&0xFF));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num == 0)
|
||||
return;
|
||||
ta = (tas/num)/255.0f;
|
||||
tr = (trs/num)/255.0f;
|
||||
tg = (tgs/num)/255.0f;
|
||||
tb = (tbs/num)/255.0f;
|
||||
if (!parts[rp>>8].dcolour)
|
||||
ta -= 3/255.0f;
|
||||
if (num == 0)
|
||||
return;
|
||||
ta = (tas/num)/255.0f;
|
||||
tr = (trs/num)/255.0f;
|
||||
tg = (tgs/num)/255.0f;
|
||||
tb = (tbs/num)/255.0f;
|
||||
if (!parts[rp>>8].dcolour)
|
||||
ta -= 3/255.0f;
|
||||
}
|
||||
}
|
||||
|
||||
ta *= 255.0f; tr *= 255.0f; tg *= 255.0f; tb *= 255.0f;
|
||||
|
Reference in New Issue
Block a user