1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 17:59:56 +00:00

made rendering more robust (no more crashes, even if Ogre throws an exception)

This commit is contained in:
Marc Zinnschlag 2010-08-25 09:43:06 +02:00
parent bdb5749b57
commit 7bb2041418
20 changed files with 81 additions and 38 deletions

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -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()));
}
}

View file

@ -1,6 +1,8 @@
#include "cellimp.hpp"
#include <cassert>
#include <iostream>
#include <exception>
#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;
}
}
}
}

View file

@ -43,6 +43,38 @@ namespace MWRender
void insertCell(ESMS::CellStore<MWWorld::RefData> &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