Pārlūkot izejas kodu

fix memory error when generateSingleBlock was called for not loaded chunks

Kolja Strohm 9 mēneši atpakaļ
vecāks
revīzija
887a728bf1

+ 1 - 0
FactoryCraft/Dimension.cpp

@@ -384,6 +384,7 @@ int Dimension::getBlockType(Framework::Vec3<int> location)
 void Dimension::placeBlock(
     Framework::Vec3<int> location, Framework::Either<Block*, int> block)
 {
+    if (block.isB() && block.getB() == BlockTypeEnum::NO_BLOCK) return;
     Chunk* c = zChunk(Game::getChunkCenter(location.x, location.y));
     if (c)
     {

+ 5 - 2
FactoryCraft/DimensionGenerator.cpp

@@ -315,11 +315,14 @@ Chunk* BiomedCavedDimensionGenerator::generateChunk(int centerX, int centerY)
 Framework::Either<Block*, int> BiomedCavedDimensionGenerator::generateBlock(
     Framework::Vec3<int> location)
 {
-    zMemory()->lock();
-
     Chunk* zChunk
         = Game::INSTANCE->zDimension(getDimensionId())
               ->zChunk(Game::INSTANCE->getChunkCenter(location.x, location.y));
+    if (!zChunk)
+    {
+        return BlockTypeEnum::NO_BLOCK;
+    }
+    zMemory()->lock();
     zMemory()->setCurrentChunk(dynamic_cast<Chunk*>(zChunk->getThis()));
 
     Framework::RCArray<GeneratedStructure>* structures

+ 1 - 0
FactoryCraft/Game.cpp

@@ -659,6 +659,7 @@ void Game::broadcastMessage(NetworkMessage* response)
     for (auto client : *clients)
         client->sendResponse(
             dynamic_cast<NetworkMessage*>(response->getThis()));
+    response->release();
 }
 
 void Game::sendMessage(NetworkMessage* response, Entity* zTargetPlayer)