From 71369be796cdba9f6e2f4b26f389d19ac55147c7 Mon Sep 17 00:00:00 2001 From: elsid Date: Thu, 2 May 2024 01:55:36 +0200 Subject: [PATCH] Log caught exceptions --- apps/openmw/mwrender/objectpaging.cpp | 4 ++- apps/openmw/mwrender/renderingmanager.cpp | 4 +-- apps/openmw/mwsound/openal_output.cpp | 4 +-- apps/openmw/mwstate/character.cpp | 10 ++++--- apps/openmw/mwworld/cell.cpp | 13 --------- apps/openmw/mwworld/cell.hpp | 8 ++++-- apps/openmw/mwworld/cellpreloader.cpp | 33 +++++++++++++---------- apps/openmw/mwworld/projectilemanager.cpp | 14 ++++++---- apps/openmw/mwworld/ptr.cpp | 15 ----------- apps/openmw/mwworld/ptr.hpp | 16 +++++++++-- apps/openmw/mwworld/scene.cpp | 8 +++--- apps/openmw/mwworld/worldimp.cpp | 31 ++++++++++++--------- components/esm/exteriorcelllocation.hpp | 6 +++++ components/resource/keyframemanager.cpp | 4 +-- components/vfs/manager.cpp | 4 +-- 15 files changed, 94 insertions(+), 80 deletions(-) diff --git a/apps/openmw/mwrender/objectpaging.cpp b/apps/openmw/mwrender/objectpaging.cpp index f3e9570aa4..a720164e03 100644 --- a/apps/openmw/mwrender/objectpaging.cpp +++ b/apps/openmw/mwrender/objectpaging.cpp @@ -511,8 +511,10 @@ namespace MWRender refs[ref.mRefNum] = std::move(ref); } } - catch (std::exception&) + catch (const std::exception& e) { + Log(Debug::Warning) << "Failed to collect references from cell \"" << cell->getDescription() + << "\": " << e.what(); continue; } } diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index dc71e455b2..f6fced3b19 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -290,9 +290,9 @@ namespace MWRender for (std::vector::const_iterator it = mKeyframes.begin(); it != mKeyframes.end(); ++it) mResourceSystem->getKeyframeManager()->get(*it); } - catch (std::exception&) + catch (const std::exception& e) { - // ignore error (will be shown when these are needed proper) + Log(Debug::Warning) << "Failed to preload common assets: " << e.what(); } } diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 0261649fa9..822c467813 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -610,9 +610,9 @@ namespace MWSound } } } - catch (std::exception&) + catch (const std::exception& e) { - Log(Debug::Error) << "Error updating stream \"" << mDecoder->getName() << "\""; + Log(Debug::Error) << "Error updating stream \"" << mDecoder->getName() << "\": " << e.what(); mIsFinished = true; } return !mIsFinished; diff --git a/apps/openmw/mwstate/character.cpp b/apps/openmw/mwstate/character.cpp index a486ff4bec..3c02311458 100644 --- a/apps/openmw/mwstate/character.cpp +++ b/apps/openmw/mwstate/character.cpp @@ -7,11 +7,11 @@ #include #include +#include #include #include -#include - #include +#include bool MWState::operator<(const Slot& left, const Slot& right) { @@ -99,9 +99,11 @@ MWState::Character::Character(const std::filesystem::path& saves, const std::str { addSlot(iter, game); } - catch (...) + catch (const std::exception& e) { - } // ignoring bad saved game files for now + Log(Debug::Warning) << "Failed to add slot for game \"" << game << "\" save " << iter << ": " + << e.what(); + } } std::sort(mSlots.begin(), mSlots.end()); diff --git a/apps/openmw/mwworld/cell.cpp b/apps/openmw/mwworld/cell.cpp index 1bd9761f72..1bc58d89c3 100644 --- a/apps/openmw/mwworld/cell.cpp +++ b/apps/openmw/mwworld/cell.cpp @@ -103,17 +103,4 @@ namespace MWWorld else mGridPos = {}; } - - ESM::RefId Cell::getWorldSpace() const - { - if (isExterior()) - return mParent; - else - return mId; - } - - ESM::ExteriorCellLocation Cell::getExteriorCellLocation() const - { - return { mGridPos.x(), mGridPos.y(), getWorldSpace() }; - } } diff --git a/apps/openmw/mwworld/cell.hpp b/apps/openmw/mwworld/cell.hpp index eab5024e12..c9586a01fa 100644 --- a/apps/openmw/mwworld/cell.hpp +++ b/apps/openmw/mwworld/cell.hpp @@ -48,8 +48,12 @@ namespace MWWorld const MoodData& getMood() const { return mMood; } float getWaterHeight() const { return mWaterHeight; } const ESM::RefId& getId() const { return mId; } - ESM::RefId getWorldSpace() const; - ESM::ExteriorCellLocation getExteriorCellLocation() const; + ESM::RefId getWorldSpace() const { return mIsExterior ? mParent : mId; } + + ESM::ExteriorCellLocation getExteriorCellLocation() const + { + return ESM::ExteriorCellLocation(mGridPos.x(), mGridPos.y(), getWorldSpace()); + } private: bool mIsExterior; diff --git a/apps/openmw/mwworld/cellpreloader.cpp b/apps/openmw/mwworld/cellpreloader.cpp index 2881471b25..0bf3360bce 100644 --- a/apps/openmw/mwworld/cellpreloader.cpp +++ b/apps/openmw/mwworld/cellpreloader.cpp @@ -66,12 +66,12 @@ namespace MWWorld { public: /// Constructor to be called from the main thread. - PreloadItem(MWWorld::CellStore* cell, Resource::SceneManager* sceneManager, + explicit PreloadItem(MWWorld::CellStore* cell, Resource::SceneManager* sceneManager, Resource::BulletShapeManager* bulletShapeManager, Resource::KeyframeManager* keyframeManager, Terrain::World* terrain, MWRender::LandManager* landManager, bool preloadInstances) : mIsExterior(cell->getCell()->isExterior()) - , mX(cell->getCell()->getGridX()) - , mY(cell->getCell()->getGridY()) + , mCellLocation(cell->getCell()->getExteriorCellLocation()) + , mCellId(cell->getCell()->getId()) , mSceneManager(sceneManager) , mBulletShapeManager(bulletShapeManager) , mKeyframeManager(keyframeManager) @@ -95,12 +95,13 @@ namespace MWWorld { try { - mTerrain->cacheCell(mTerrainView.get(), mX, mY); - mPreloadedObjects.insert( - mLandManager->getLand(ESM::ExteriorCellLocation(mX, mY, ESM::Cell::sDefaultWorldspaceId))); + mTerrain->cacheCell(mTerrainView.get(), mCellLocation.mX, mCellLocation.mY); + mPreloadedObjects.insert(mLandManager->getLand(mCellLocation)); } - catch (std::exception&) + catch (const std::exception& e) { + Log(Debug::Warning) << "Failed to cache terrain for exterior cell " << mCellLocation << ": " + << e.what(); } } @@ -113,8 +114,12 @@ namespace MWWorld try { + const VFS::Manager& vfs = *mSceneManager->getVFS(); mesh = Misc::ResourceHelpers::correctMeshPath(path); - mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, mSceneManager->getVFS()); + mesh = Misc::ResourceHelpers::correctActorModelPath(mesh, &vfs); + + if (!vfs.exists(mesh)) + continue; size_t slashpos = mesh.find_last_of("/\\"); if (slashpos != std::string::npos && slashpos != mesh.size() - 1) @@ -124,7 +129,7 @@ namespace MWWorld { kfname = mesh; kfname.replace(kfname.size() - 4, 4, ".kf"); - if (mSceneManager->getVFS()->exists(kfname)) + if (vfs.exists(kfname)) mPreloadedObjects.insert(mKeyframeManager->get(kfname)); } } @@ -134,18 +139,18 @@ namespace MWWorld else mPreloadedObjects.insert(mBulletShapeManager->getShape(mesh)); } - catch (std::exception&) + catch (const std::exception& e) { - // ignore error for now, would spam the log too much - // error will be shown when visiting the cell + Log(Debug::Warning) << "Failed to preload mesh \"" << path << "\" from cell " << mCellId << ": " + << e.what(); } } } private: bool mIsExterior; - int mX; - int mY; + ESM::ExteriorCellLocation mCellLocation; + ESM::RefId mCellId; std::vector mMeshes; Resource::SceneManager* mSceneManager; Resource::BulletShapeManager* mBulletShapeManager; diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 4daa85a450..dc675d956a 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -705,8 +705,10 @@ namespace MWWorld state.mProjectileId = mPhysics->addProjectile(state.getCaster(), osg::Vec3f(esm.mPosition), model, false); } - catch (...) + catch (const std::exception& e) { + Log(Debug::Warning) << "Failed to add projectile for " << esm.mId + << " while reading projectile record: " << e.what(); return true; } @@ -734,10 +736,10 @@ namespace MWWorld state.mEffects = getMagicBoltData( state.mIdMagic, state.mSoundIds, state.mSpeed, texture, state.mSourceName, state.mSpellId); } - catch (...) + catch (const std::exception& e) { - Log(Debug::Warning) << "Warning: Failed to recreate magic projectile from saved data (id \"" - << state.mSpellId << "\" no longer exists?)"; + Log(Debug::Warning) << "Failed to recreate magic projectile for " << esm.mId << " and spell " + << state.mSpellId << " while reading projectile record: " << e.what(); return true; } @@ -753,8 +755,10 @@ namespace MWWorld MWWorld::Ptr ptr = ref.getPtr(); model = ptr.getClass().getCorrectedModel(ptr); } - catch (...) + catch (const std::exception& e) { + Log(Debug::Warning) << "Failed to get model for " << state.mIdMagic.at(0) + << " while reading projectile record: " << e.what(); return true; } diff --git a/apps/openmw/mwworld/ptr.cpp b/apps/openmw/mwworld/ptr.cpp index 25715a26f1..8b3f77e805 100644 --- a/apps/openmw/mwworld/ptr.cpp +++ b/apps/openmw/mwworld/ptr.cpp @@ -6,21 +6,6 @@ namespace MWWorld { - - std::string Ptr::toString() const - { - std::string res = "object"; - if (mRef->isDeleted()) - res = "deleted object"; - res.append(getCellRef().getRefNum().toString()); - res.append(" ("); - res.append(getTypeDescription()); - res.append(", "); - res.append(getCellRef().getRefId().toDebugString()); - res.append(")"); - return res; - } - SafePtr::SafePtr(const Ptr& ptr) : mId(ptr.getCellRef().getRefNum()) , mPtr(ptr) diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 85fef8d9fb..41398296e3 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -98,6 +98,20 @@ namespace MWWorld return mContainerStore; } + std::string toString() const + { + if (mRef == nullptr) + return "null object"; + std::string result = mRef->isDeleted() ? "object" : "deleted object"; + result += mRef->mRef.getRefNum().toString(); + result += " ("; + result += mRef->getTypeDescription(); + result += ", "; + result += mRef->mRef.getRefId().toDebugString(); + result += ")"; + return result; + } + template