Forráskód Böngészése

Fixed #229, #290.
Fixed problems with accessing shared memory sometimes occurring after application has previously crashed.

Michał W. Urbańczyk 16 éve
szülő
commit
d037bec1be
4 módosított fájl, 6 hozzáadás és 4 törlés
  1. 2 1
      client/Client.cpp
  2. 2 2
      int3.h
  3. 1 0
      lib/CGameState.cpp
  4. 1 1
      server/CGameHandler.cpp

+ 2 - 1
client/Client.cpp

@@ -90,10 +90,11 @@ void CClient::init()
 	gs = NULL;
 	cb = NULL;
 	terminate = false;
+	boost::interprocess::shared_memory_object::remove("vcmi_memory"); //if the application has previously crashed, the memory may not have been removed. to avoid problems - try to destroy it
 	try
 	{
 		shared = new SharedMem();
-	} HANDLE_EXCEPTION
+	} HANDLE_EXCEPTIONC(tlog1 << "Cannot open interprocess memory: ";)
 }
 
 CClient::CClient(void)

+ 2 - 2
int3.h

@@ -78,7 +78,7 @@ public:
 			TCreature id = slots[preferable].first;
 			for(TSlots::const_iterator j=slots.begin(); j!=slots.end(); ++j)
 			{
-				if(id == j->second.first)
+				if(id == j->second.first && j->first != preferable)
 				{
 					out.first = preferable;
 					out.second = j->first;
@@ -91,7 +91,7 @@ public:
 		{
 			for(TSlots::const_iterator j=slots.begin(); j!=slots.end(); ++j)
 			{
-				if(i->second.first == j->second.first)
+				if(i->second.first == j->second.first  &&  i->first != j->first)
 				{
 					out.first = i->first;
 					out.second = j->first;

+ 1 - 0
lib/CGameState.cpp

@@ -2011,6 +2011,7 @@ bool CGameState::getPath(int3 src, int3 dest, const CGHeroInstance * hero, CPath
 void CGameState::calculatePaths(const CGHeroInstance *hero, CPathsInfo &out, int3 src, int movement)
 {
 	assert(hero);
+	boost::shared_lock<boost::shared_mutex> lock(*mx);
 	if(src.x < 0)
 		src = hero->getPosition(false);
 	if(movement < 0)

+ 1 - 1
server/CGameHandler.cpp

@@ -2217,7 +2217,7 @@ bool CGameHandler::upgradeCreature( ui32 objid, ui8 pos, ui32 upgID )
 bool CGameHandler::garrisonSwap( si32 tid )
 {
 	CGTownInstance *town = gs->getTown(tid);
-	if(!town->garrisonHero && town->visitingHero) //visiting => garrison, merge armies
+	if(!town->garrisonHero && town->visitingHero) //visiting => garrison, merge armies: town army => hero army
 	{
 		CCreatureSet csn = town->visitingHero->army, cso = town->army;
 		while(!cso.slots.empty())//while there are unmoved creatures