From 70b0547499c4343e3071a54e3c093712669a3a8f Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Thu, 15 May 2014 16:03:45 +0200 Subject: Fixed a NULL ptr failure in GridStructGen. When the descendant generator returned a NULL structure, the generator would crash. Now it uses a special cEmptyStructure class instead. --- src/Generating/GridStructGen.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/Generating/GridStructGen.cpp') diff --git a/src/Generating/GridStructGen.cpp b/src/Generating/GridStructGen.cpp index 3bbc89054..23946e2e9 100644 --- a/src/Generating/GridStructGen.cpp +++ b/src/Generating/GridStructGen.cpp @@ -9,6 +9,34 @@ +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cEmptyStructure: + +/** A cStructure descendant representing an empty structure. +Used when the generator descended from cGridStructGen doesn't return any structure, to keep at least the +Origin coords so that the structure isn't queried over and over again. */ +class cEmptyStructure : + public cGridStructGen::cStructure +{ + typedef cGridStructGen::cStructure super; + +public: + cEmptyStructure(int a_OriginX, int a_OriginZ) : + super(a_OriginX, a_OriginZ) + { + } + +protected: + virtual void DrawIntoChunk(cChunkDesc & a_ChunkDesc) override + { + // Do nothing + } +} ; + + + + + cGridStructGen::cGridStructGen( int a_Seed, int a_GridSizeX, int a_GridSizeZ, @@ -81,7 +109,12 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur } // for itr - a_Structures[] if (!Found) { - a_Structures.push_back(CreateStructure(OriginX, OriginZ)); + cStructurePtr Structure = CreateStructure(OriginX, OriginZ); + if (Structure.get() == NULL) + { + Structure.reset(new cEmptyStructure(OriginX, OriginZ)); + } + a_Structures.push_back(Structure); } } // for z } // for x -- cgit v1.2.3