diff --git a/apps/openmw/mwphysics/physicssystem.cpp b/apps/openmw/mwphysics/physicssystem.cpp index 8bf0e39240..8db390a6ea 100644 --- a/apps/openmw/mwphysics/physicssystem.cpp +++ b/apps/openmw/mwphysics/physicssystem.cpp @@ -822,7 +822,8 @@ namespace MWPhysics // copy new ptr position in temporary vector. player is handled separately as its movement might change active // cell. mActorsPositions.clear(); - mActorsPositions.reserve(mActors.size() - 1); + if (!mActors.empty()) + mActorsPositions.reserve(mActors.size() - 1); for (const auto& [ptr, physicActor] : mActors) { if (physicActor.get() == player) @@ -833,7 +834,8 @@ namespace MWPhysics for (const auto& [ptr, pos] : mActorsPositions) world->moveObject(ptr, pos, false, false); - world->moveObject(player->getPtr(), player->getSimulationPosition(), false, false); + if (player != nullptr) + world->moveObject(player->getPtr(), player->getSimulationPosition(), false, false); } void PhysicsSystem::updateAnimatedCollisionShape(const MWWorld::Ptr& object) diff --git a/components/resource/objectcache.hpp b/components/resource/objectcache.hpp index 65b2606b06..6c155b9ec6 100644 --- a/components/resource/objectcache.hpp +++ b/components/resource/objectcache.hpp @@ -61,7 +61,8 @@ namespace Resource { // If ref count is greater than 1, the object has an external reference. // If the timestamp is yet to be initialized, it needs to be updated too. - if (itr->second.first->referenceCount() > 1 || itr->second.second == 0.0) + if ((itr->second.first != nullptr && itr->second.first->referenceCount() > 1) + || itr->second.second == 0.0) itr->second.second = referenceTime; } }