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

Fix crash on defeating hero in boat

This commit is contained in:
Ivan Savenko 2023-03-22 00:38:55 +02:00
parent bb03abdce6
commit a78f7de9cd

View File

@ -251,6 +251,26 @@ void MapViewController::fadeInObject(const CGObjectInstance * obj)
void MapViewController::removeObject(const CGObjectInstance * obj) void MapViewController::removeObject(const CGObjectInstance * obj)
{ {
if (obj->ID == Obj::BOAT)
{
auto * boat = dynamic_cast<const CGBoat*>(obj);
if (boat->hero)
{
view->invalidate(context, boat->hero->id);
state->removeObject(boat->hero);
}
}
if (obj->ID == Obj::HERO)
{
auto * hero = dynamic_cast<const CGHeroInstance*>(obj);
if (hero->boat)
{
view->invalidate(context, hero->boat->id);
state->removeObject(hero->boat);
}
}
view->invalidate(context, obj->id); view->invalidate(context, obj->id);
state->removeObject(obj); state->removeObject(obj);
} }
@ -265,7 +285,7 @@ void MapViewController::onBeforeHeroEmbark(const CGHeroInstance * obj, const int
{ {
if(isEventVisible(obj, from, dest)) if(isEventVisible(obj, from, dest))
{ {
onObjectFadeOut(obj); fadeOutObject(obj);
setViewCenter(obj->getSightCenter()); setViewCenter(obj->getSightCenter());
} }
else else
@ -288,7 +308,7 @@ void MapViewController::onAfterHeroDisembark(const CGHeroInstance * obj, const i
{ {
if(isEventVisible(obj, from, dest)) if(isEventVisible(obj, from, dest))
{ {
onObjectFadeIn(obj); fadeInObject(obj);
setViewCenter(obj->getSightCenter()); setViewCenter(obj->getSightCenter());
} }
addObject(obj); addObject(obj);