Fix Chunk destructor segfault using smart pointers #112 (#414)

This commit is contained in:
ModMaker101
2026-03-04 10:43:29 -05:00
committed by GitHub
parent ca5fde56fe
commit 2be856a2d4
2 changed files with 12 additions and 14 deletions

View File

@@ -52,7 +52,7 @@ Chunk::Chunk(Level *level, LevelRenderer::rteMap &globalRenderableTileEntities,
: globalRenderableTileEntities( &globalRenderableTileEntities ), globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs) : globalRenderableTileEntities( &globalRenderableTileEntities ), globalRenderableTileEntities_cs(&globalRenderableTileEntities_cs)
{ {
clipChunk->visible = false; clipChunk->visible = false;
bb = NULL; bb = nullptr;
id = 0; id = 0;
this->level = level; this->level = level;
@@ -101,9 +101,9 @@ void Chunk::setPos(int x, int y, int z)
float g = 6.0f; float g = 6.0f;
// 4J - changed to just set the value rather than make a new one, if we've already created storage // 4J - changed to just set the value rather than make a new one, if we've already created storage
if( bb == NULL ) if( !bb )
{ {
bb = AABB::newPermanent(-g, -g, -g, XZSIZE+g, SIZE+g, XZSIZE+g); bb = shared_ptr<AABB>(AABB::newPermanent(-g, -g, -g, XZSIZE+g, SIZE+g, XZSIZE+g));
} }
else else
{ {
@@ -154,6 +154,7 @@ void Chunk::translateToPos()
Chunk::Chunk() Chunk::Chunk()
{ {
bb = nullptr;
} }
void Chunk::makeCopyForRebuild(Chunk *source) void Chunk::makeCopyForRebuild(Chunk *source)
@@ -998,7 +999,7 @@ int Chunk::getList(int layer)
void Chunk::cull(Culler *culler) void Chunk::cull(Culler *culler)
{ {
clipChunk->visible = culler->isVisible(bb); clipChunk->visible = culler->isVisible(bb.get());
} }
void Chunk::renderBB() void Chunk::renderBB()
@@ -1027,10 +1028,7 @@ void Chunk::clearDirty()
#endif #endif
} }
Chunk::~Chunk() Chunk::~Chunk() = default;
{
delete bb;
}
bool Chunk::emptyFlagSet(int layer) bool Chunk::emptyFlagSet(int layer)
{ {

View File

@@ -47,7 +47,7 @@ public:
int xRenderOffs, yRenderOffs, zRenderOffs; int xRenderOffs, yRenderOffs, zRenderOffs;
int xm, ym, zm; int xm, ym, zm;
AABB *bb; shared_ptr<AABB> bb;
ClipChunk *clipChunk; ClipChunk *clipChunk;
int id; int id;