From 5350f98e8da517cbd44568e75d13ed5302de9a78 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 11 Mar 2021 20:31:43 +0100 Subject: [PATCH] Fix automapper crash (fixes #3675) Thanks to bojidar-bg for the way to fix, verified locally --- src/game/editor/auto_map.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/game/editor/auto_map.cpp b/src/game/editor/auto_map.cpp index 7e77ad179..a3f366cc7 100644 --- a/src/game/editor/auto_map.cpp +++ b/src/game/editor/auto_map.cpp @@ -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)