diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 5800656a..ab942ed7 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -877,6 +877,7 @@ Command *Unit::getCurrrentCommandThreadSafe() { if(commands.empty() == false) { return commands.front(); } + return NULL; } @@ -1078,6 +1079,7 @@ CommandResult Unit::cancelCommand() { this->unitPath->clear(); safeMutex.ReleaseLock(); + return crSuccess; } @@ -2087,6 +2089,7 @@ void Unit::clearCommands() { delete commands.back(); commands.pop_back(); } + safeMutex.ReleaseLock(); } void Unit::deleteQueuedCommand(Command *command) { diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index e0b09591..97b43cf7 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -292,7 +292,8 @@ void World::updateAllFactionUnits() { unitsInFactionsSorted[faction->getIndex()].push_back(CommandGroupSorter(unit)); } - std::sort(unitsInFactionsSorted[faction->getIndex()].begin(),unitsInFactionsSorted[faction->getIndex()].end()); + std::vector &unitListToSort = unitsInFactionsSorted[faction->getIndex()]; + std::sort(unitListToSort.begin(),unitListToSort.end()); } // Signal the faction threads to do any pre-processing @@ -301,7 +302,8 @@ void World::updateAllFactionUnits() { if(faction == NULL) { throw runtime_error("faction == NULL"); } - faction->signalWorkerThread(frameCount,&unitsInFactionsSorted[faction->getIndex()]); + std::vector &unitListSorted = unitsInFactionsSorted[faction->getIndex()]; + faction->signalWorkerThread(frameCount,&unitListSorted); } bool workThreadsFinished = false; @@ -338,9 +340,11 @@ void World::updateAllFactionUnits() { throw runtime_error("faction == NULL"); } - int unitCount = unitsInFactionsSorted[faction->getIndex()].size(); + std::vector &unitListSorted = unitsInFactionsSorted[faction->getIndex()]; + + int unitCount = unitListSorted.size(); for(int j = 0; j < unitCount; ++j) { - Unit *unit = unitsInFactionsSorted[faction->getIndex()][j].unit; + Unit *unit = unitListSorted[j].unit; if(unit == NULL) { throw runtime_error("unit == NULL"); }