Handling Exceptions Raised By Mogre

WarehouseJim

22-04-2010 14:04:03

To summarise an issue I first raised on the Mogre 1.6.5 discussion:



As a more general criticism, I find with my projects that it's a nightmare to work out why Mogre isn't working, with cryptic / misleading exception messages e.g. "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." More usefully in ogre.log it says: "14:29:01: OGRE EXCEPTION(7:InternalErrorException): C:/MogreSDK/Media/packs/OgreCore.zip - error whilst opening archive: Unable to read zip file. in ZipArchive::checkZzipError at ..\src\OgreZip.cpp (line 259)"

That's because you're swallowing SEHExceptions somewhere, like:

try
{
MyApp app = new MyApp ();
}
catch (System.Runtime.InteropServices.SEHException)
{
if (OgreException.LastException != null)
LogManager.Singleton.LogMessage(OgreException.LastException.FullDescription);
else
throw;
}

The AccessViolationException is only a followup.


This is similar to the suggestion about how to catch exceptions in Tutorial 0, however, it doesn't catch my exception which can be recreated (good enough) by changing the name of C:\MogreSDK\Media\packs (assuming you use a zip from within it).

So I did some digging around and http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.sehexception.aspx suggests that actually what would have been a SEHException is often actually re-mapped to a number of different exceptions, including AccessViolationException. If I catch the AccessViolationException, then I can view the Ogre exception using the above code.

Am I doing something different, or should the advice be changed to catch all the exceptions in the link (OutOfMemoryException, AccessViolationException, [NullReferenceException]) explicitly? If it makes any difference, I'm using .NET 3.5 & C# 3.0.

smiley80

22-04-2010 15:56:17


(...)however, it doesn't catch my exception which can be recreated (good enough) by changing the name of C:\MogreSDK\Media\packs (assuming you use a zip from within it).

It should catch the exception (otherwise it wouldn't log it), but it also swallows it (removing the 'else' fixes that). Any following exception is likely to be caused by a now unstable Ogre.


Am I doing something different, or should the advice be changed to catch all the exceptions in the link (OutOfMemoryException, AccessViolationException, [NullReferenceException]) explicitly? If it makes any difference, I'm using .NET 3.5 & C# 3.0.

I don't think that Ogre::Exceptions get remapped to anything other than SEHExceptions.

boyamer

22-04-2010 16:36:12

I can confirm too,Exception from Ogre/Mogre are SEHExceptions in .net

WarehouseJim

22-04-2010 17:24:51

I swear I searched my project for "SEHException"! You're totally right, I was catching the SEHException in a different place and swallowing it.

BTW It appears that it still logs the exception in ogre.log without the LogManager.Singleton.LogMessage(OgreException.LastException.FullDescription); I searched twice for both LogManager and LogMessage this time to check.

thanks for the help.