From 62e8815f5a4ea0cb94034f1f03d4f6df934c1e32 Mon Sep 17 00:00:00 2001 From: Omar Aglan Date: Mon, 28 Sep 2026 17:47:12 +0300 Subject: [PATCH] bugfix(worldbuilder): Roll back failed blend allocations --- .../Tools/WorldBuilder/src/WHeightMapEdit.cpp | 38 +++++++++++-------- .../Tools/WorldBuilder/src/WHeightMapEdit.cpp | 38 +++++++++++-------- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index 09bbaf42c5b..b67ebe03b30 100644 --- a/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -1171,31 +1171,39 @@ void WorldHeightMapEdit::blendSpecificTiles(Int xIndex, Int yIndex, Int srcXInde if (baseBlendInfo && baseIsDiagonal && baseNeedsFlip != flipped) return; //the base requires a certain flip state which we can't alter so can't apply extra blend here. } - updateFlatCellForAdjacentCliffs(xIndex, yIndex, getTextureClassFromNdx(blendTileNdx)); - //Check if this tile is really necessary or if the base blend already does the same thing as the 3way blend. - if (baseBlendInfo && baseBlendInfo->blendNdx == blendTileNdx) + if (baseBlendInfo && baseBlendInfo->blendNdx == blendTileNdx) { + updateFlatCellForAdjacentCliffs(xIndex, yIndex, getTextureClassFromNdx(blendTileNdx)); return; + } + Int oldNumBlendedTiles = m_numBlendedTiles; Short newNdx = findOrCreateBlendTile(&blendInfo); if (newNdx >= 0) { - Int ndx = (yIndex*m_width)+xIndex; + Short newBaseNdx = m_blendTileNdxes[ndx]; + //force the primary layer to flip if the extra blend layer needs flip. + //we only do this on vertical/horizontal base blends because they work in either flip cases. + if (baseBlendInfo && flipped && !baseIsDiagonal) + { + //Find a new tile so as not to affect other cells using the base one. + TBlendTileInfo tempBlendTileInfo = *baseBlendInfo; + tempBlendTileInfo.inverted |= FLIPPED_MASK; + newBaseNdx = findOrCreateBlendTile(&tempBlendTileInfo); + if (newBaseNdx < 0) { + // Discard any secondary record allocated by this failed edit. + m_numBlendedTiles = oldNumBlendedTiles; + return; + } + } + + updateFlatCellForAdjacentCliffs(xIndex, yIndex, getTextureClassFromNdx(blendTileNdx)); m_tileNdxes[ndx] = curTileNdx; - if (TheGlobalData->m_use3WayTerrainBlends && m_blendTileNdxes[ndx] != 0) + if (baseBlendInfo) { //this tile already has a blend applied to it. So we put the new blend into the //secondary layer. m_extraBlendTileNdxes[ndx]=newNdx; - //force the primary layer to flip if the extra blend layer needs flip. - //we only do this on vertical/horizontal base blends because they work in either flip cases. - if (flipped && !baseIsDiagonal) - { - //Find a new tile so as not to affect other cells using the base one. - TBlendTileInfo tempBlendTileInfo=m_blendedTiles[m_blendTileNdxes[ndx]]; - tempBlendTileInfo.inverted |= FLIPPED_MASK; - Short newNdx = findOrCreateBlendTile(&tempBlendTileInfo); - m_blendTileNdxes[ndx] = newNdx; //remap this tile to use a new one. - } + m_blendTileNdxes[ndx] = newBaseNdx; //remap this tile to use a new one. } else m_blendTileNdxes[ndx] = newNdx; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp index e409b2a42f2..0cbd37971f8 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/WHeightMapEdit.cpp @@ -1171,31 +1171,39 @@ void WorldHeightMapEdit::blendSpecificTiles(Int xIndex, Int yIndex, Int srcXInde if (baseBlendInfo && baseIsDiagonal && baseNeedsFlip != flipped) return; //the base requires a certain flip state which we can't alter so can't apply extra blend here. } - updateFlatCellForAdjacentCliffs(xIndex, yIndex, getTextureClassFromNdx(blendTileNdx)); - //Check if this tile is really necessary or if the base blend already does the same thing as the 3way blend. - if (baseBlendInfo && baseBlendInfo->blendNdx == blendTileNdx) + if (baseBlendInfo && baseBlendInfo->blendNdx == blendTileNdx) { + updateFlatCellForAdjacentCliffs(xIndex, yIndex, getTextureClassFromNdx(blendTileNdx)); return; + } + Int oldNumBlendedTiles = m_numBlendedTiles; Short newNdx = findOrCreateBlendTile(&blendInfo); if (newNdx >= 0) { - Int ndx = (yIndex*m_width)+xIndex; + Short newBaseNdx = m_blendTileNdxes[ndx]; + //force the primary layer to flip if the extra blend layer needs flip. + //we only do this on vertical/horizontal base blends because they work in either flip cases. + if (baseBlendInfo && flipped && !baseIsDiagonal) + { + //Find a new tile so as not to affect other cells using the base one. + TBlendTileInfo tempBlendTileInfo = *baseBlendInfo; + tempBlendTileInfo.inverted |= FLIPPED_MASK; + newBaseNdx = findOrCreateBlendTile(&tempBlendTileInfo); + if (newBaseNdx < 0) { + // Discard any secondary record allocated by this failed edit. + m_numBlendedTiles = oldNumBlendedTiles; + return; + } + } + + updateFlatCellForAdjacentCliffs(xIndex, yIndex, getTextureClassFromNdx(blendTileNdx)); m_tileNdxes[ndx] = curTileNdx; - if (TheGlobalData->m_use3WayTerrainBlends && m_blendTileNdxes[ndx] != 0) + if (baseBlendInfo) { //this tile already has a blend applied to it. So we put the new blend into the //secondary layer. m_extraBlendTileNdxes[ndx]=newNdx; - //force the primary layer to flip if the extra blend layer needs flip. - //we only do this on vertical/horizontal base blends because they work in either flip cases. - if (flipped && !baseIsDiagonal) - { - //Find a new tile so as not to affect other cells using the base one. - TBlendTileInfo tempBlendTileInfo=m_blendedTiles[m_blendTileNdxes[ndx]]; - tempBlendTileInfo.inverted |= FLIPPED_MASK; - Short newNdx = findOrCreateBlendTile(&tempBlendTileInfo); - m_blendTileNdxes[ndx] = newNdx; //remap this tile to use a new one. - } + m_blendTileNdxes[ndx] = newBaseNdx; //remap this tile to use a new one. } else m_blendTileNdxes[ndx] = newNdx;