diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ceffc8f1d..53b8284f1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -178,6 +178,7 @@ Bug #5211: Screen fades in if the first loaded save is in interior cell Bug #5213: SameFaction script function is broken Bug #5218: Crash when disabling ToggleBorders + Bug #5220: GetLOS crashes when actor isn't loaded Feature #1774: Handle AvoidNode Feature #2229: Improve pathfinding AI Feature #3025: Analogue gamepad movement controls diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index 0bb94a1342..23ebfcb839 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -382,9 +382,11 @@ namespace MWScript std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->getPtr(actorID, true); + MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false); - Interpreter::Type_Integer value = MWBase::Environment::get().getMechanicsManager()->isActorDetected(actor, observer); + Interpreter::Type_Integer value = 0; + if (!actor.isEmpty()) + value = MWBase::Environment::get().getMechanicsManager()->isActorDetected(actor, observer); runtime.push (value); } @@ -404,9 +406,9 @@ namespace MWScript runtime.pop(); - MWWorld::Ptr dest = MWBase::Environment::get().getWorld()->getPtr(actorID,true); + MWWorld::Ptr dest = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false); bool value = false; - if(dest != MWWorld::Ptr() && source.getClass().isActor() && dest.getClass().isActor()) + if (!dest.isEmpty() && source.getClass().isActor() && dest.getClass().isActor()) { value = MWBase::Environment::get().getWorld()->getLOS(source,dest); } @@ -447,8 +449,9 @@ namespace MWScript std::string targetID = runtime.getStringLiteral (runtime[0].mInteger); runtime.pop(); - MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr(targetID, true); - MWBase::Environment::get().getMechanicsManager()->startCombat(actor, target); + MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false); + if (!target.isEmpty()) + MWBase::Environment::get().getMechanicsManager()->startCombat(actor, target); } }; diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index bc6f9ea8e7..d40ad769d6 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -1129,7 +1129,9 @@ namespace MWScript return; } - MWWorld::Ptr target = MWBase::Environment::get().getWorld()->getPtr (targetId, false); + MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetId, false, false); + if (target.isEmpty()) + return; MWMechanics::CastSpell cast(ptr, target, false, true); cast.playSpellCastingEffects(spell->mId, false);