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.
This commit is contained in:
parent
56f7ad2cd9
commit
70b0547499
@ -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(
|
cGridStructGen::cGridStructGen(
|
||||||
int a_Seed,
|
int a_Seed,
|
||||||
int a_GridSizeX, int a_GridSizeZ,
|
int a_GridSizeX, int a_GridSizeZ,
|
||||||
@ -81,7 +109,12 @@ void cGridStructGen::GetStructuresForChunk(int a_ChunkX, int a_ChunkZ, cStructur
|
|||||||
} // for itr - a_Structures[]
|
} // for itr - a_Structures[]
|
||||||
if (!Found)
|
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 z
|
||||||
} // for x
|
} // for x
|
||||||
|
@ -39,14 +39,6 @@ class cGridStructGen :
|
|||||||
public cFinishGen
|
public cFinishGen
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
cGridStructGen(
|
|
||||||
int a_Seed,
|
|
||||||
int a_GridSizeX, int a_GridSizeZ,
|
|
||||||
int a_MaxStructureSizeX, int a_MaxStructureSizeZ,
|
|
||||||
size_t a_MaxCacheSize
|
|
||||||
);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
/** Represents a single structure that occupies the grid point. Knows how to draw itself into a chunk. */
|
/** Represents a single structure that occupies the grid point. Knows how to draw itself into a chunk. */
|
||||||
class cStructure
|
class cStructure
|
||||||
{
|
{
|
||||||
@ -75,6 +67,14 @@ protected:
|
|||||||
typedef std::list<cStructurePtr> cStructurePtrs;
|
typedef std::list<cStructurePtr> cStructurePtrs;
|
||||||
|
|
||||||
|
|
||||||
|
cGridStructGen(
|
||||||
|
int a_Seed,
|
||||||
|
int a_GridSizeX, int a_GridSizeZ,
|
||||||
|
int a_MaxStructureSizeX, int a_MaxStructureSizeZ,
|
||||||
|
size_t a_MaxCacheSize
|
||||||
|
);
|
||||||
|
|
||||||
|
protected:
|
||||||
/** Seed for generating the semi-random grid. */
|
/** Seed for generating the semi-random grid. */
|
||||||
int m_Seed;
|
int m_Seed;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user