Fail more gracefully?

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Fail more gracefully?

Post by lonewolff »

Hi guys,

Is there a way to make Ogre fail more gracefully?

For example, if you attempt to create an entity an mis-spell the mesh name, Ogre will throw an exception.

Is there a way to have a fallback so the application will continue without an exception?

I have tried this, but it is the first line the exception occurs on.

Code: Select all

Entity *mEntity=mSceneMgr->createEntity(name,model_name);

if(!mEntity)
	return 1;
I'd rather be able to test if a call succeeded rather than have the entire application go 'BANG!' :lol:
User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm
x 12

Re: Fail more gracefully?

Post by cybereality »

I assume you can just wrap the call in a try/catch statement. Have you tried that?
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fail more gracefully?

Post by lonewolff »

Thanks for the reply.

No i haven't tried that. I'll take a look at doing something like that :)
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: Fail more gracefully?

Post by areay »

I think you're asking more about Ogre in general, but for that specific case, you could always query Ogre to find out if that mesh is registered.

Ogre::MeshManager::getSingetonPtr()->getByName(...) which returns null if it's not there.

I think you'd need to have called Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups() first. HTH
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fail more gracefully?

Post by lonewolff »

Cool that will help (in some areas of my code).

But there is also the times where a mesh might be mistyped (or even removed from the media repo). I'd prefer to handle the error more nicely that to have an exception thrown and application ended.

Even if I could say 'well that mesh file isn't there so load a rectangle instead'. That sort of thing :)

[edit]
The reason behind this is that I am midway through writing an extension for Game Maker:Studio using Ogre as the renderer and all is working exceptionally well. So, it is more of an ease of use thing from the end user perspective. Rather than have them think the extension is 'crap' because they made a mistake and the application throws exceptions all over the place :)

And as we know with Ogre (and any other API for that matter) it is pretty easy to make a mistake and have things break. :)

I think it should be upto the coder to decide if something is a 'show stopper' and not th API.
amartin
Halfling
Posts: 87
Joined: Wed Aug 14, 2013 6:55 am
Location: Norway
x 13

Re: Fail more gracefully?

Post by amartin »

The crash hard on missing resources makes sense in most cases since it's better to find out early that stuff is missing than to have holes in your game. If by the time you get around to rendering resources are missing you've probably missed a step as a developer.

When you create things that may or may not exist is when you should check to see if the resources are available from the relevant manager and create a placeholder if they don't exist. That also gives you the power to decide how you want to handle the issue before it gets to the point that the rendering has to handle an incomplete resource during the render cycle. I'm fairly sure that the managers have the methods you need for this as I was planning to do this in my game to allow for use generated meshes to be used instead of my default resources.
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Fail more gracefully?

Post by frostbyte »

maybe this will help : https://bitbucket.org/clb/ogre-safe-nocrashes/
mainted by http://realxtend.org/
updated to ogre 1.9....
lots of commits - not sure if it will help in this case - but i think i saw some commits regarding resource-loading fails...threre is a commit-search-bar...
if you try and use this branch - i would be happy to hear about your experience...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Fail more gracefully?

Post by lonewolff »

Thanks for that, I might give that a try at some stage. :)

Also with the 'try / catch' method. Will this still terminate the program or do you have a choice as to what the 'catch' does? As I haven't used this method much in the past.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Fail more gracefully?

Post by c6burns »

the catch block is for gracefully handling any exception thrown in the try block. Personally I don't like using exceptions unless absolutely necessary. There can be performance considerations depending on the implementation, but more than anything I'm just used to C where there are no exceptions
Post Reply