1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-22 00:27:58 +02:00

Fix crashes on game start, gamestate now derives from GameCallbackHolder

This commit is contained in:
Ivan Savenko
2025-04-01 15:59:08 +03:00
parent d34b47bb20
commit d1d2cf4189
21 changed files with 99 additions and 81 deletions

View File

@@ -505,7 +505,10 @@ void CMap::generateUniqueInstanceName(CGObjectInstance * target)
void CMap::addNewObject(std::shared_ptr<CGObjectInstance> obj)
{
if(obj->id != ObjectInstanceID(static_cast<si32>(objects.size())))
if (!obj->id.hasValue())
obj->id = ObjectInstanceID(objects.size());
if(obj->id != ObjectInstanceID(objects.size()) && objects.at(obj->id.getNum()) != nullptr)
throw std::runtime_error("Invalid object instance id");
if(obj->instanceName.empty())
@@ -766,17 +769,27 @@ CArtifactInstance * CMap::createScroll(const SpellID & spellId)
CArtifactInstance * CMap::createSingleArtifact(const ArtifactID & artId, const SpellID & spellId)
{
return new CArtifactInstance(cb);
auto newArtifact = artId.hasValue() ?
std::make_shared<CArtifactInstance>(cb, artId.toArtifact()):
std::make_shared<CArtifactInstance>(cb);
newArtifact->setId(ArtifactInstanceID(artInstances.size()));
artInstances.push_back(newArtifact);
return newArtifact.get();
}
CArtifactInstance * CMap::createArtifact(const ArtifactID & artID, const SpellID & spellId)
{
if(!artID.hasValue())
return new CArtifactInstance(cb); // random, empty //TODO: make this illegal & remove?
{
// random, empty
// TODO: make this illegal & remove? Such artifact can't be randomized as combined artifact later
return createSingleArtifact(artID, spellId);
}
auto art = artID.toArtifact();
auto artInst = new CArtifactInstance(cb, art);
auto artInst = createSingleArtifact(artID, spellId);
if(art->isCombined() && !art->isFused())
{
for(const auto & part : art->getConstituents())