1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

Fixed possible use-after-free crash with artifacts registration in RMG.

This commit is contained in:
AlexVinS
2016-09-08 14:47:43 +03:00
parent 6dc47a2de0
commit 42e7128acc
2 changed files with 8 additions and 1 deletions

View File

@@ -591,6 +591,14 @@ void CMap::addNewObject(CGObjectInstance * obj)
quests.push_back(q->quest);
}
break;
case Obj::SPELL_SCROLL:
{
CGArtifact * art = dynamic_cast<CGArtifact *>(obj);
if(art->storedArtifact && art->storedArtifact->id.getNum() < 0)
addNewArtifactInstance(art->storedArtifact);
}
break;
default:
break;
}

View File

@@ -2522,7 +2522,6 @@ void CRmgTemplateZone::addAllPossibleObjects(CMapGenerator* gen)
}
}
auto a = CArtifactInstance::createScroll(RandomGeneratorUtil::nextItem(out, gen->rand)->toSpell());
gen->map->addNewArtifactInstance(a);
obj->storedArtifact = a;
return obj;
};