From 69c76acabb72b451048483685c95d3003cad0b47 Mon Sep 17 00:00:00 2001 From: wraitii Date: Mon, 9 May 2022 17:31:00 +0000 Subject: [PATCH] Fix crash in non-visual autostart from not loading terrain textures Fixes 410d2e883a Reported by: langbart Differential Revision: https://code.wildfiregames.com/D4627 This was SVN commit r26866. --- source/graphics/MapReader.cpp | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index fe6d7df54d..f9dc99ac5f 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -247,7 +247,7 @@ int CMapReader::UnpackTerrain() CStr texturename; unpacker.UnpackString(texturename); - if(CTerrainTextureManager::IsInitialised()) + if (CTerrainTextureManager::IsInitialised()) { CTerrainTextureEntry* texentry = g_TexMan.FindTexture(texturename); m_TerrainTextures.push_back(texentry); @@ -281,18 +281,21 @@ int CMapReader::ApplyTerrainData() // initialise the terrain pTerrain->Initialize(m_PatchesPerSide, &m_Heightmap[0]); - // setup the textures on the minipatches - STileDesc* tileptr = &m_Tiles[0]; - for (ssize_t j=0; jGetPatch(i,j)->m_MiniPatches[m][k]; // can't fail + if (CTerrainTextureManager::IsInitialised()) + { + // setup the textures on the minipatches + STileDesc* tileptr = &m_Tiles[0]; + for (ssize_t j=0; jGetPatch(i,j)->m_MiniPatches[m][k]; // can't fail - mp.Tex = m_TerrainTextures[tileptr->m_Tex1Index]; - mp.Priority = tileptr->m_Priority; + mp.Tex = m_TerrainTextures[tileptr->m_Tex1Index]; + mp.Priority = tileptr->m_Priority; - tileptr++; + tileptr++; + } } } } @@ -560,8 +563,9 @@ void CXMLReader::ReadTerrain(XMBElement parent) m_MapReader.m_PatchesPerSide = patches; // Load the texture - ENSURE(CTerrainTextureManager::IsInitialised()); // we need this for the terrain properties (even when graphics are disabled) - CTerrainTextureEntry* texentry = g_TexMan.FindTexture(texture); + CTerrainTextureEntry* texentry = nullptr; + if (CTerrainTextureManager::IsInitialised()) + texentry = g_TexMan.FindTexture(texture); m_MapReader.pTerrain->Initialize(patches, NULL);