Selaa lähdekoodia

fix some multithreading crashes

Kolja Strohm 2 vuotta sitten
vanhempi
commit
840dc49d37

+ 4 - 4
FactoryCraft/Chunk.cpp

@@ -166,7 +166,8 @@ void Chunk::setBlock(Block* block)
 void Chunk::removeBlock(Block* zBlock)
 {
 	cs.lock();
-	for (Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++)
+	vcs.lock();
+	for (Framework::Iterator<Block*> iterator = visibleBlocks.begin(); iterator; iterator++)
 	{
 		if (zBlock == (Block*)iterator)
 		{
@@ -174,8 +175,8 @@ void Chunk::removeBlock(Block* zBlock)
 			break;
 		}
 	}
-	vcs.lock();
-	for (Framework::Iterator<Block*> iterator = visibleBlocks.begin(); iterator; iterator++)
+	vcs.unlock();
+	for (Framework::Iterator<Block*> iterator = blocks.begin(); iterator; iterator++)
 	{
 		if (zBlock == (Block*)iterator)
 		{
@@ -183,7 +184,6 @@ void Chunk::removeBlock(Block* zBlock)
 			break;
 		}
 	}
-	vcs.unlock();
 	cs.unlock();
 }
 

+ 1 - 1
FactoryCraft/Constants.h

@@ -2,5 +2,5 @@
 
 #define CHUNK_SIZE 16
 #define WORLD_HEIGHT 500
-#define CHUNK_VISIBILITY_RANGE 4
+#define CHUNK_VISIBILITY_RANGE 1
 #define MAX_VIEW_DISTANCE CHUNK_SIZE * CHUNK_VISIBILITY_RANGE

+ 1 - 1
FactoryCraft/Dialog.cpp

@@ -21,7 +21,7 @@ UIMLDialog::UIMLDialog(Framework::Text uiml, std::function<void(UIMLDialog* self
 	view->addKnownElement(new EquipmentElement());
 	view->addKnownElement(new CraftingGridElement());
 	view->setUIML(xml);
-	view->setSize(xml->getAttributeValue("width"), xml->getAttributeValue("height"));
+	view->setSize((int)xml->getAttributeValue("width"), (int)xml->getAttributeValue("height"));
 	name = xml->getAttributeValue("id");
 	view->layout();
 	addMember(view);

+ 3 - 0
FactoryCraft/Dimension.cpp

@@ -146,10 +146,13 @@ void Dimension::setChunk(Chunk* chunk, Punkt center)
 	else if (chunk)
 		chunkList.add(chunk);
 	chunks->set(addr, 8, chunk);
+	if (chunk)
+		chunk->getThis();
 	cs.unlock();
 	if (chunk)
 	{
 		currentGame->setVisibility(chunk, 1);
+		chunk->release();
 	}
 }
 

+ 1 - 1
FactoryCraft/Load.cpp

@@ -167,7 +167,7 @@ void createCubeItem(Bildschirm* zScreen)
 	data->setAmbientFactor(0.8f);
 	data->setDiffusFactor(0.1f);
 	data->setSpecularFactor(0.1f);
-	float size = 0.2;
+	float size = 0.2f;
 	float left, right, top, bottom;
 	// Calculate the screen coordinates of the left side of the bitmap.
 	left = (float)((-size / 2.0));