Browse Source

fix crash when a rendered block is replaced by another block

Kolja Strohm 2 years ago
parent
commit
c971f69bfe
1 changed files with 9 additions and 3 deletions
  1. 9 3
      FactoryCraft/Chunk.cpp

+ 9 - 3
FactoryCraft/Chunk.cpp

@@ -167,14 +167,15 @@ void Chunk::setBlock(Block* block)
             {
                 if ((Block*)iterator == (Block*)vi)
                 {
-                    iterator.remove();
+                    vi.remove();
                     break;
                 }
             }
             vcs.unlock();
             iterator->release();
             iterator.set(block);
-            break;
+            cs.unlock();
+            return;
         }
     }
     blocks.add(block);
@@ -266,7 +267,12 @@ void Chunk::load(Framework::StreamReader* zReader)
                         zB->setLightData(
                             getOppositeDirection(getDirectionFromIndex(i)),
                             (unsigned char*)lightData);
-                        if (zB->isVisible() && !visible) visibleBlocks.add(zB);
+                        if (zB->isVisible() && !visible)
+                        {
+                            vcs.lock();
+                            visibleBlocks.add(zB);
+                            vcs.unlock();
+                        }
                     }
                 }
                 else