3694: Fix automapper crash (fixes #3675) r=Learath2 a=def-

Thanks to bojidar-bg for the way to fix, verified locally

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-03-20 16:31:58 +00:00 committed by GitHub
commit daef3d6c98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -397,25 +397,17 @@ void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed,
int UpdateToX = clamp(X + Width + 3 * pConf->m_EndX, 0, pLayer->m_Width);
int UpdateToY = clamp(Y + Height + 3 * pConf->m_EndY, 0, pLayer->m_Height);
CLayerTiles *pUpdateLayer;
if(UpdateFromX != 0 || UpdateFromY != 0 || UpdateToX != pLayer->m_Width || UpdateToY != pLayer->m_Width)
{ // Needs a layer to work on
pUpdateLayer = new CLayerTiles(UpdateToX - UpdateFromX, UpdateToY - UpdateFromY);
CLayerTiles *pUpdateLayer = new CLayerTiles(UpdateToX - UpdateFromX, UpdateToY - UpdateFromY);
for(int y = UpdateFromY; y < UpdateToY; y++)
{
for(int x = UpdateFromX; x < UpdateToX; x++)
{
CTile *in = &pLayer->m_pTiles[y * pLayer->m_Width + x];
CTile *out = &pUpdateLayer->m_pTiles[(y - UpdateFromY) * pUpdateLayer->m_Width + x - UpdateFromX];
out->m_Index = in->m_Index;
out->m_Flags = in->m_Flags;
}
}
}
else
for(int y = UpdateFromY; y < UpdateToY; y++)
{
pUpdateLayer = pLayer;
for(int x = UpdateFromX; x < UpdateToX; x++)
{
CTile *in = &pLayer->m_pTiles[y * pLayer->m_Width + x];
CTile *out = &pUpdateLayer->m_pTiles[(y - UpdateFromY) * pUpdateLayer->m_Width + x - UpdateFromX];
out->m_Index = in->m_Index;
out->m_Flags = in->m_Flags;
}
}
Proceed(pUpdateLayer, ConfigID, Seed, UpdateFromX, UpdateFromY);
@ -431,8 +423,7 @@ void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed,
}
}
if(pUpdateLayer)
delete pUpdateLayer;
delete pUpdateLayer;
}
void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedOffsetX, int SeedOffsetY)