Преглед на файлове

fix memory error when connection to server is lost

Kolja Strohm преди 1 година
родител
ревизия
42dd8c98b2
променени са 3 файла, в които са добавени 26 реда и са изтрити 24 реда
  1. 24 22
      FactoryCraft/ChunkFluidModel.cpp
  2. 1 1
      FactoryCraft/Menu.cpp
  3. 1 1
      FactoryCraft/World.cpp

+ 24 - 22
FactoryCraft/ChunkFluidModel.cpp

@@ -242,38 +242,40 @@ void ChunkFluidModel::buildModel()
 bool ChunkFluidModel::updateLightning()
 {
     __int64* lightBuffer = target->zLightBuffer();
+    int oldVertexCount = target->getVertexAnzahl();
     int groundVertexCount = 0;
     for (int i = 0; i < CHUNK_SIZE * CHUNK_SIZE * WORLD_HEIGHT; i++)
     {
-        if (blocks()[i])
+        if (blocks()[i] && (blocks()[i]->getPartOfModels() | getType()) )
         {
-            if (blocks()[i]
-                    ->zBlockType()->isFluid())
+            int index = 0;
+            for (Text* textureName :
+                *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
             {
-                int index = 0;
-                for (Text* textureName :
-                    *blocks()[i]->zBlockType()->getModelInfo().getTexturNames())
+                Framework::Vec3<int> location(
+                    (i / WORLD_HEIGHT) / CHUNK_SIZE,
+                    (i / WORLD_HEIGHT) % CHUNK_SIZE,
+                    i % WORLD_HEIGHT);
+                if (isPartOfGroundModel(location, index))
                 {
-                    Framework::Vec3<int> location(
-                        (i / WORLD_HEIGHT) / CHUNK_SIZE,
-                        (i / WORLD_HEIGHT) % CHUNK_SIZE,
-                        i % WORLD_HEIGHT);
-                    if (isPartOfGroundModel(location, index))
+                    const Vertex3D* vBuffer
+                        = blocks()[i]->zModelData()->zVertexBuffer();
+                    Polygon3D* polygon
+                        = blocks()[i]->zModelData()->getPolygon(index);
+                    for (int vi = 0; vi < polygon->indexAnz; vi++)
                     {
-                        const Vertex3D* vBuffer
-                            = blocks()[i]->zModelData()->zVertexBuffer();
-                        Polygon3D* polygon
-                            = blocks()[i]->zModelData()->getPolygon(index);
-                        for (int vi = 0; vi < polygon->indexAnz; vi++)
+                        if (oldVertexCount <= groundVertexCount)
                         {
-                            lightBuffer[groundVertexCount++] = calculateLight(
-                                vBuffer[polygon->indexList[vi]].pos,
-                                location,
-                                getDirectionFromIndex(index));
-                        }
+                                std::cout << "ERROR: to many vertecies in chunk fluid model" << std::endl;
+                            return 0;
+						}
+                        lightBuffer[groundVertexCount++] = calculateLight(
+                            vBuffer[polygon->indexList[vi]].pos,
+                            location,
+                            getDirectionFromIndex(index));
                     }
-                    index++;
                 }
+                index++;
             }
         }
     }

+ 1 - 1
FactoryCraft/Menu.cpp

@@ -15,7 +15,7 @@ void Menu::show()
 
 void Menu::hide()
 {
-    new AsynchronCall([this]() {
+    zScreen->postAction([this]() {
         for (auto member : elements)
             zScreen->removeMember(dynamic_cast<Zeichnung*>(member->getThis()));
     });

+ 1 - 1
FactoryCraft/World.cpp

@@ -356,12 +356,12 @@ void World::thread()
     std::cout << "background connection lost\n";
     menuRegister->get("game")->hide();
     menuRegister->get("serverSelection")->show();
-    release();
     zScreenPtr->unlock();
     zScreenPtr->postAction([this]() {
         if (World::INSTANCE == this)
         {
             World::INSTANCE = 0;
+            release();
         }
     });
 }