Merge branch 'fix_7420' into 'master'

Fix #7420 (Local scripts on items cause the game to crash when activated)

Closes #7420

See merge request OpenMW/openmw!3131
revert-6246b479
psi29a 2 years ago
commit 428642d2cf

@ -63,7 +63,7 @@ namespace MWLua
LocalScripts(LuaUtil::LuaState* lua, const LObject& obj);
MWBase::LuaManager::ActorControls* getActorControls() { return &mData.mControls; }
const MWWorld::Ptr& getPtr() const { return mData.ptr(); }
const MWWorld::Ptr& getPtrOrEmpty() const { return mData.ptrOrEmpty(); }
void setActive(bool active);
void onConsume(const LObject& consumable) { callEngineHandlers(mOnConsumeHandlers, consumable); }

@ -141,8 +141,9 @@ namespace MWLua
mWorldView.update();
std::erase_if(mActiveLocalScripts,
[](const LocalScripts* l) { return l->getPtr().isEmpty() || l->getPtr().getRefData().isDeleted(); });
std::erase_if(mActiveLocalScripts, [](const LocalScripts* l) {
return l->getPtrOrEmpty().isEmpty() || l->getPtrOrEmpty().getRefData().isDeleted();
});
mGlobalScripts.statsNextFrame();
for (LocalScripts* scripts : mActiveLocalScripts)

@ -31,7 +31,7 @@ namespace MWLua
using SafePtr::SafePtr;
const MWWorld::Ptr& ptr() const
{
const MWWorld::Ptr& res = ptrOrNull();
const MWWorld::Ptr& res = ptrOrEmpty();
if (res.isEmpty())
throw std::runtime_error("Object is not available: " + id().toString());
return res;

@ -152,7 +152,7 @@ namespace MWLua
return sol::nullopt;
return Misc::StringUtils::lowerCase(contentList[contentFileIndex]);
});
objectT["isValid"] = [](const ObjectT& o) { return !o.ptrOrNull().isEmpty(); };
objectT["isValid"] = [](const ObjectT& o) { return !o.ptrOrEmpty().isEmpty(); };
objectT["recordId"] = sol::readonly_property(
[](const ObjectT& o) -> std::string { return o.ptr().getCellRef().getRefId().serializeText(); });
objectT["cell"] = sol::readonly_property([](const ObjectT& o) -> sol::optional<Cell<ObjectT>> {

@ -165,7 +165,7 @@ namespace MWWorld
std::string toString() const;
const Ptr& ptrOrNull() const
const Ptr& ptrOrEmpty() const
{
update();
return mPtr;

Loading…
Cancel
Save