Runtime exception loading overlays

Problems building or running the engine, queries about how to use features etc.
Post Reply
Mattkingc
Gnoblar
Posts: 5
Joined: Tue May 15, 2018 10:02 pm

Runtime exception loading overlays

Post by Mattkingc »

I am trying to use SDKTrays and have changed my application to try and load the correct overlays but I get an odd error where it tries to load the SdkTray.fontdef file twice. It seems like when looking at the SDKTray.zip file it tried to load the SdkTrays.fondef file twice (which then causes the exception) and I can't figure out why.
I'm using version Ogre 1.11

The error I get is:
Parsing scripts for resource group Essential
Parsing script SdkTrays.material
Parsing script OgreProfiler.material
Parsing script SdkTrays.fontdef
Parsing script SdkTrays.fontdef
terminate called after throwing an instance of 'Ogre::ItemIdentityException'
what(): ItemIdentityException: Resource with the name SdkTrays/Caption already exists. in ResourceManager::add at /Repo/ogre/OgreMain/src/OgreResourceManager.cpp (line 155)


The following is the code I changed to try and get the code overlays:

Code: Select all

 
 Ogre::OverlaySystem* overlaySystem = new Ogre::OverlaySystem();
 Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Essential");
 tray_manager_ = new OgreBites::TrayManager("Sensitivity",render_window,this);
  
I've tried the sample applications and they seem to load the overlays properly.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Runtime exception loading overlays

Post by dark_sylinc »

The most reasonable explanation is that you have the SdkTrays.fontdef file twice: once in the zip file, another loose somewhere in the folders you load.
Mattkingc
Gnoblar
Posts: 5
Joined: Tue May 15, 2018 10:02 pm

Re: Runtime exception loading overlays

Post by Mattkingc »

I wish that were the case, but if I remove the SdkTrays.fontdef file from the Zip then the fontdef file doesn't get loaded at all. I also tried loading the file directly, and unzipping it and loading the directory, all with the same results.

If I move the fontdef information into the overlay file then I can get past everything but then when I try to create the trayManager I get an error that SdkTray/Cursor is not found so it also must not be parsing the SdkTrays.overlay file correctly, even though it says it is parsing that script.
Mattkingc
Gnoblar
Posts: 5
Joined: Tue May 15, 2018 10:02 pm

Re: Runtime exception loading overlays

Post by Mattkingc »

So it turns out that my issue was that there were multiple calls to:

Code: Select all

Ogre::OverlaySystem* overlaySystem = new Ogre::OverlaySystem();
in different classes.

For each one it tries to load the fondef file once you load resources, thus resulting in the duplication error.

This also cause my problem with the missing overlays because if you do the following:

Code: Select all

new Ogre::OverlaySystem();
Ogre::OverlayManager& mOverlayMgr_1 = Ogre::OverlayManager::getSingleton();
new Ogre::OverlaySystem();
Ogre::OverlayManager& mOverlayMgr_2 = Ogre::OverlayManager::getSingleton();
The first and second overlay managers are actually different (which is a little confusing since normally you expect singletons to always return the same object).
paroj
OGRE Team Member
OGRE Team Member
Posts: 1995
Joined: Sun Mar 30, 2014 2:51 pm
x 1075
Contact:

Re: Runtime exception loading overlays

Post by paroj »

there is an assert in the ogre singleton implementation - however it will only trigger when ogre is compiled as debug. Probably we should enable that in all build modes.
Mattkingc
Gnoblar
Posts: 5
Joined: Tue May 15, 2018 10:02 pm

Re: Runtime exception loading overlays

Post by Mattkingc »

I certainly would have appreciated it, :D Took me a long time to figure out the problem, because the stray OverlaySystem call was in a class that I had never even looked at. I imagine the performance hit would be trivial since you aren't creating singletons very often. I guess it's also a lesson for me to also compile in debug.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1280
Contact:

Re: Runtime exception loading overlays

Post by dark_sylinc »

Actually there is an assert that will be tested every time getSingleton gets called, not just during construction.

It is strongly advised you use Debug mode and not just Release mode, as Ogre has additional sanity checks to warn you about invalid data, usage, incorrect params, etc.

Cheers
Matias
Mattkingc
Gnoblar
Posts: 5
Joined: Tue May 15, 2018 10:02 pm

Re: Runtime exception loading overlays

Post by Mattkingc »

The assert you are talking about checks if the Singleton is null. I agree that should only be in debug since it runs often, and for my case it would have passed anyways since I was double creating the singleton, not failing to create it at all.

The one I thought would be nice to check in release and debug is on the creation of the Singleton itself, since I assume that happens much more rarely.

Code: Select all

 Singleton( void )
        {
            assert( !msSingleton ); 
replace with

Code: Select all

 Singleton( void )
        {
            if ( msSingleton );
            throw (...) 
I could easily be missing something or other considerations make this unreasonable. And, thanks, I am building in Debug now to make sure I catch other issues.
Post Reply