1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Merge pull request #4316 from IvanSavenko/crashfixes

Crashfixes
This commit is contained in:
Ivan Savenko 2024-07-21 16:15:28 +03:00 committed by GitHub
commit 550540f8ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 65 additions and 59 deletions

View File

@ -291,10 +291,9 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
std::vector<BattleHex> copy = targetHexes; std::vector<BattleHex> copy = targetHexes;
for(auto hex : copy) for(auto hex : copy)
{
vstd::concatenate(targetHexes, hex.allNeighbouringTiles()); vstd::concatenate(targetHexes, hex.allNeighbouringTiles());
}
vstd::erase_if(targetHexes, [](const BattleHex & hex) {return !hex.isValid();});
vstd::removeDuplicates(targetHexes); vstd::removeDuplicates(targetHexes);
} }

View File

@ -33,6 +33,9 @@ bool CAnimation::loadFrame(size_t frame, size_t group)
if(image) if(image)
{ {
images[group][frame] = image; images[group][frame] = image;
if (player.isValidPlayer())
image->playerColored(player);
return true; return true;
} }
else else
@ -188,8 +191,9 @@ void CAnimation::verticalFlip(size_t frame, size_t group)
source[group][frame] = locator; source[group][frame] = locator;
} }
void CAnimation::playerColored(PlayerColor player) void CAnimation::playerColored(PlayerColor targetPlayer)
{ {
player = targetPlayer;
for(auto & group : images) for(auto & group : images)
for(auto & image : group.second) for(auto & image : group.second)
image.second->playerColored(player); image.second->playerColored(player);

View File

@ -157,10 +157,7 @@ struct DLL_LINKAGE LobbyStartGame : public CLobbyPackToPropagate
{ {
h & clientId; h & clientId;
h & initializedStartInfo; h & initializedStartInfo;
bool sps = h.smartPointerSerialization;
h.smartPointerSerialization = true;
h & initializedGameState; h & initializedGameState;
h.smartPointerSerialization = sps;
} }
}; };

View File

@ -37,39 +37,44 @@ public:
/// Effectively revesed version of BinarySerializer /// Effectively revesed version of BinarySerializer
class BinaryDeserializer : public CLoaderBase class BinaryDeserializer : public CLoaderBase
{ {
template<typename Ser,typename T> template<typename Fake, typename T>
struct LoadIfStackInstance static bool loadIfStackInstance(T &data)
{ {
static bool invoke(Ser &s, T &data) return false;
{ }
return false;
}
};
template<typename Ser> template<typename Fake>
struct LoadIfStackInstance<Ser, CStackInstance *> bool loadIfStackInstance(const CStackInstance* &data)
{ {
static bool invoke(Ser &s, CStackInstance* &data) CArmedInstance * armyPtr = nullptr;
ObjectInstanceID armyID;
SlotID slot;
load(armyID);
load(slot);
if (armyID == ObjectInstanceID::NONE)
return false;
if(reader->smartVectorMembersSerialization)
{ {
CArmedInstance *armedObj; if(const auto *info = reader->getVectorizedTypeInfo<CArmedInstance, ObjectInstanceID>())
SlotID slot; armyPtr = static_cast<CArmedInstance *>(reader->getVectorItemFromId<CArmedInstance, ObjectInstanceID>(*info, armyID));
s.load(armedObj);
s.load(slot);
if(slot != SlotID::COMMANDER_SLOT_PLACEHOLDER)
{
assert(armedObj->hasStackAtSlot(slot));
data = armedObj->stacks[slot];
}
else
{
auto * hero = dynamic_cast<CGHeroInstance *>(armedObj);
assert(hero);
assert(hero->commander);
data = hero->commander;
}
return true;
} }
};
if(slot != SlotID::COMMANDER_SLOT_PLACEHOLDER)
{
assert(armyPtr->hasStackAtSlot(slot));
data = armyPtr->stacks[slot];
}
else
{
auto * hero = dynamic_cast<CGHeroInstance *>(armyPtr);
assert(hero);
assert(hero->commander);
data = hero->commander;
}
return true;
}
template <typename T, typename Enable = void> template <typename T, typename Enable = void>
struct ClassObjectCreator struct ClassObjectCreator
@ -331,7 +336,7 @@ public:
if(reader->sendStackInstanceByIds) if(reader->sendStackInstanceByIds)
{ {
bool gotLoaded = LoadIfStackInstance<BinaryDeserializer,T>::invoke(* this, data); bool gotLoaded = loadIfStackInstance<void>(data);
if(gotLoaded) if(gotLoaded)
return; return;
} }

View File

@ -52,33 +52,33 @@ class BinarySerializer : public CSaverBase
} }
}; };
template<typename Ser,typename T> template<typename Fake, typename T>
struct SaveIfStackInstance bool saveIfStackInstance(const T &data)
{ {
static bool invoke(Ser &s, const T &data) return false;
{ }
return false;
}
};
template<typename Ser> template<typename Fake>
struct SaveIfStackInstance<Ser, CStackInstance *> bool saveIfStackInstance(const CStackInstance* const &data)
{ {
static bool invoke(Ser &s, const CStackInstance* const &data) assert(data->armyObj);
{
assert(data->armyObj);
SlotID slot;
if(data->getNodeType() == CBonusSystemNode::COMMANDER) SlotID slot;
slot = SlotID::COMMANDER_SLOT_PLACEHOLDER;
else
slot = data->armyObj->findStack(data);
assert(slot != SlotID()); if(data->getNodeType() == CBonusSystemNode::COMMANDER)
s & data->armyObj & slot; slot = SlotID::COMMANDER_SLOT_PLACEHOLDER;
else
slot = data->armyObj->findStack(data);
assert(slot != SlotID());
save(data->armyObj->id);
save(slot);
if (data->armyObj->id != ObjectInstanceID::NONE)
return true; return true;
} else
}; return false;
}
template <typename T> class CPointerSaver; template <typename T> class CPointerSaver;
@ -252,7 +252,7 @@ public:
if(writer->sendStackInstanceByIds) if(writer->sendStackInstanceByIds)
{ {
const bool gotSaved = SaveIfStackInstance<BinarySerializer,T>::invoke(*this, data); const bool gotSaved = saveIfStackInstance<void>(data);
if(gotSaved) if(gotSaved)
return; return;
} }

View File

@ -84,6 +84,7 @@ void CConnection::sendPack(const CPack * pack)
connectionPtr->sendPacket(packWriter->buffer); connectionPtr->sendPacket(packWriter->buffer);
packWriter->buffer.clear(); packWriter->buffer.clear();
serializer->savedPointers.clear();
} }
CPack * CConnection::retrievePack(const std::vector<std::byte> & data) CPack * CConnection::retrievePack(const std::vector<std::byte> & data)
@ -102,6 +103,8 @@ CPack * CConnection::retrievePack(const std::vector<std::byte> & data)
throw std::runtime_error("Failed to retrieve pack! Not all data has been read!"); throw std::runtime_error("Failed to retrieve pack! Not all data has been read!");
logNetwork->trace("Received CPack of type %s", typeid(*result).name()); logNetwork->trace("Received CPack of type %s", typeid(*result).name());
deserializer->loadedPointers.clear();
deserializer->loadedSharedPointers.clear();
return result; return result;
} }
@ -132,7 +135,6 @@ void CConnection::enterLobbyConnectionMode()
deserializer->loadedPointers.clear(); deserializer->loadedPointers.clear();
serializer->savedPointers.clear(); serializer->savedPointers.clear();
disableSmartVectorMemberSerialization(); disableSmartVectorMemberSerialization();
disableSmartPointerSerialization();
disableStackSendingByID(); disableStackSendingByID();
} }
@ -144,7 +146,6 @@ void CConnection::setCallback(IGameCallback * cb)
void CConnection::enterGameplayConnectionMode(CGameState * gs) void CConnection::enterGameplayConnectionMode(CGameState * gs)
{ {
enableStackSendingByID(); enableStackSendingByID();
disableSmartPointerSerialization();
setCallback(gs->callback); setCallback(gs->callback);
enableSmartVectorMemberSerializatoin(gs); enableSmartVectorMemberSerializatoin(gs);