From df178ed97c457bdc906fa23dc4c7f0ee000181ac Mon Sep 17 00:00:00 2001 From: AnyOldName3 Date: Fri, 16 Oct 2020 19:54:26 +0000 Subject: [PATCH] Merge branch 'container-regressions' into 'master' Fix container regressions See merge request OpenMW/openmw!346 (cherry picked from commit b0aee6f83d4cddb0116284b197913f9687dd9cee) 95e7a22d fix container regressions --- apps/openmw/mwgui/container.cpp | 16 +++++++++------- components/misc/rng.cpp | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index 810a369d8..fdb27addc 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -230,36 +230,38 @@ namespace MWGui { MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mCloseButton); + // Copy mPtr because onTakeAllButtonClicked closes the window which resets the reference + MWWorld::Ptr ptr = mPtr; onTakeAllButtonClicked(mTakeButton); - if (mPtr.getClass().isPersistent(mPtr)) + if (ptr.getClass().isPersistent(ptr)) MWBase::Environment::get().getWindowManager()->messageBox("#{sDisposeCorpseFail}"); else { - MWMechanics::CreatureStats& creatureStats = mPtr.getClass().getCreatureStats(mPtr); + MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); // If we dispose corpse before end of death animation, we should update death counter counter manually. // Also we should run actor's script - it may react on actor's death. if (creatureStats.isDead() && !creatureStats.isDeathAnimationFinished()) { creatureStats.setDeathAnimationFinished(true); - MWBase::Environment::get().getMechanicsManager()->notifyDied(mPtr); + MWBase::Environment::get().getMechanicsManager()->notifyDied(ptr); - const std::string script = mPtr.getClass().getScript(mPtr); + const std::string script = ptr.getClass().getScript(ptr); if (!script.empty() && MWBase::Environment::get().getWorld()->getScriptsEnabled()) { - MWScript::InterpreterContext interpreterContext (&mPtr.getRefData().getLocals(), mPtr); + MWScript::InterpreterContext interpreterContext (&ptr.getRefData().getLocals(), ptr); MWBase::Environment::get().getScriptManager()->run (script, interpreterContext); } // Clean up summoned creatures as well std::map& creatureMap = creatureStats.getSummonedCreatureMap(); for (const auto& creature : creatureMap) - MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(mPtr, creature.second); + MWBase::Environment::get().getMechanicsManager()->cleanupSummonedCreature(ptr, creature.second); creatureMap.clear(); } - MWBase::Environment::get().getWorld()->deleteObject(mPtr); + MWBase::Environment::get().getWorld()->deleteObject(ptr); } mPtr = MWWorld::Ptr(); diff --git a/components/misc/rng.cpp b/components/misc/rng.cpp index 4189404b1..23d820448 100644 --- a/components/misc/rng.cpp +++ b/components/misc/rng.cpp @@ -30,17 +30,17 @@ namespace Misc float Rng::rollProbability(Seed& seed) { - return std::uniform_real_distribution(0, 1 - std::numeric_limits::epsilon())(sSeed.mGenerator); + return std::uniform_real_distribution(0, 1 - std::numeric_limits::epsilon())(seed.mGenerator); } float Rng::rollClosedProbability(Seed& seed) { - return std::uniform_real_distribution(0, 1)(sSeed.mGenerator); + return std::uniform_real_distribution(0, 1)(seed.mGenerator); } int Rng::rollDice(int max, Seed& seed) { - return max > 0 ? std::uniform_int_distribution(0, max - 1)(sSeed.mGenerator) : 0; + return max > 0 ? std::uniform_int_distribution(0, max - 1)(seed.mGenerator) : 0; } unsigned int Rng::generateDefaultSeed()