diff --git a/apps/openmw/mwclass/activator.cpp b/apps/openmw/mwclass/activator.cpp index 69a5108030..6c96811d8a 100644 --- a/apps/openmw/mwclass/activator.cpp +++ b/apps/openmw/mwclass/activator.cpp @@ -21,9 +21,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/apparatus.cpp b/apps/openmw/mwclass/apparatus.cpp index 007b2ca77f..1d4afc0960 100644 --- a/apps/openmw/mwclass/apparatus.cpp +++ b/apps/openmw/mwclass/apparatus.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/armor.cpp b/apps/openmw/mwclass/armor.cpp index 5c06077b20..1217d56a69 100644 --- a/apps/openmw/mwclass/armor.cpp +++ b/apps/openmw/mwclass/armor.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/book.cpp b/apps/openmw/mwclass/book.cpp index 179a060c6a..3679eb7eea 100644 --- a/apps/openmw/mwclass/book.cpp +++ b/apps/openmw/mwclass/book.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/clothing.cpp b/apps/openmw/mwclass/clothing.cpp index c3bbfa9f0f..07ded02640 100644 --- a/apps/openmw/mwclass/clothing.cpp +++ b/apps/openmw/mwclass/clothing.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 9c1ed7a897..ea61508b8d 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -21,9 +21,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index fc9515fff6..2e16ac6a43 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -33,9 +33,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/door.cpp b/apps/openmw/mwclass/door.cpp index 12aeb9a5b9..e8c41dc751 100644 --- a/apps/openmw/mwclass/door.cpp +++ b/apps/openmw/mwclass/door.cpp @@ -27,9 +27,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/ingredient.cpp b/apps/openmw/mwclass/ingredient.cpp index 29d66d0128..e4ea509f91 100644 --- a/apps/openmw/mwclass/ingredient.cpp +++ b/apps/openmw/mwclass/ingredient.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/light.cpp b/apps/openmw/mwclass/light.cpp index e57511452b..de5c06a73e 100644 --- a/apps/openmw/mwclass/light.cpp +++ b/apps/openmw/mwclass/light.cpp @@ -28,7 +28,7 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); @@ -40,7 +40,7 @@ namespace MWClass const float radius = float (ref->base->data.radius); cellRender.insertLight (r, g, b, radius); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/lockpick.cpp b/apps/openmw/mwclass/lockpick.cpp index c87d1e128f..3b08ff199a 100644 --- a/apps/openmw/mwclass/lockpick.cpp +++ b/apps/openmw/mwclass/lockpick.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/misc.cpp b/apps/openmw/mwclass/misc.cpp index 57dca31481..d4ffdce380 100644 --- a/apps/openmw/mwclass/misc.cpp +++ b/apps/openmw/mwclass/misc.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 0fdc779639..04ae468e42 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -40,7 +40,8 @@ namespace MWClass std::string headModel = "meshes\\" + environment.mWorld->getStore().bodyParts.find(headID)->model; - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); + cellRender.insertMesh (headModel); //TODO: define consts for each bodypart e.g. chest, foot, wrist... and put the parts in the @@ -51,7 +52,7 @@ namespace MWClass if (bodyPart) cellRender.insertMesh("meshes\\" + bodyPart->model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } void Npc::enable (const MWWorld::Ptr& ptr, MWWorld::Environment& environment) const diff --git a/apps/openmw/mwclass/potion.cpp b/apps/openmw/mwclass/potion.cpp index 3fe38542ba..e163473f75 100644 --- a/apps/openmw/mwclass/potion.cpp +++ b/apps/openmw/mwclass/potion.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/probe.cpp b/apps/openmw/mwclass/probe.cpp index bc6c4ba196..9188ae9ea3 100644 --- a/apps/openmw/mwclass/probe.cpp +++ b/apps/openmw/mwclass/probe.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/repair.cpp b/apps/openmw/mwclass/repair.cpp index 253569afe6..7b42bc95cc 100644 --- a/apps/openmw/mwclass/repair.cpp +++ b/apps/openmw/mwclass/repair.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/static.cpp b/apps/openmw/mwclass/static.cpp index 211d239c60..33e3e0ed42 100644 --- a/apps/openmw/mwclass/static.cpp +++ b/apps/openmw/mwclass/static.cpp @@ -19,9 +19,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwclass/weapon.cpp b/apps/openmw/mwclass/weapon.cpp index 5a941360af..4c14e58ea9 100644 --- a/apps/openmw/mwclass/weapon.cpp +++ b/apps/openmw/mwclass/weapon.cpp @@ -24,9 +24,9 @@ namespace MWClass const std::string &model = ref->base->model; if (!model.empty()) { - cellRender.insertBegin (ref->ref); + MWRender::Rendering rendering (cellRender, ref->ref); cellRender.insertMesh ("meshes\\" + model); - ref->mData.setHandle (cellRender.insertEnd (ref->mData.isEnabled())); + ref->mData.setHandle (rendering.end (ref->mData.isEnabled())); } } diff --git a/apps/openmw/mwrender/cellimp.cpp b/apps/openmw/mwrender/cellimp.cpp index a5b4b51c77..887941f059 100644 --- a/apps/openmw/mwrender/cellimp.cpp +++ b/apps/openmw/mwrender/cellimp.cpp @@ -1,6 +1,8 @@ #include "cellimp.hpp" #include +#include +#include #include "../mwworld/class.hpp" #include "../mwworld/ptr.hpp" @@ -23,8 +25,16 @@ void insertCellRefList (CellRenderImp& cellRender, MWWorld::Environment& environ { MWWorld::Ptr ptr (&*it, &cell); - class_.insertObj (ptr, cellRender, environment); - class_.enable (ptr, environment); + try + { + class_.insertObj (ptr, cellRender, environment); + class_.enable (ptr, environment); + } + catch (const std::exception& e) + { + std::string error ("error during rendering: "); + std::cerr << error + e.what() << std::endl; + } } } } diff --git a/apps/openmw/mwrender/cellimp.hpp b/apps/openmw/mwrender/cellimp.hpp index fadba79a55..bc6f2874a0 100644 --- a/apps/openmw/mwrender/cellimp.hpp +++ b/apps/openmw/mwrender/cellimp.hpp @@ -43,6 +43,38 @@ namespace MWRender void insertCell(ESMS::CellStore &cell, MWWorld::Environment& environment); }; + + /// Exception-safe rendering + class Rendering + { + CellRenderImp& mCellRender; + bool mEnd; + + // not implemented + Rendering (const Rendering&); + Rendering& operator= (const Rendering&); + + public: + + Rendering (CellRenderImp& cellRender, ESM::CellRef &ref) + : mCellRender (cellRender), mEnd (false) + { + mCellRender.insertBegin (ref); + } + + ~Rendering() + { + if (!mEnd) + mCellRender.insertEnd (false); + } + + std::string end (bool enable) + { + assert (!mEnd); + mEnd = true; + return mCellRender.insertEnd (enable); + } + }; } #endif