#ifdef conditionals in header files

Discussion area about developing or extending OGRE, adding plugins for it or building applications on it. No newbie questions please, use the Help forum for that.
Post Reply
rogual
Gnoblar
Posts: 21
Joined: Sun Mar 01, 2015 9:33 pm
x 4

#ifdef conditionals in header files

Post by rogual »

Hey folks

Using Ogre 2.0 here.

I just spent a while debugging an issue that turned out to be caused by a class layout mismatch between my app and Ogre.

In OgreNode.h there's this conditional:

Code: Select all

#ifndef NDEBUG
        mutable bool mCachedTransformOutOfDate;
#endif
This means that, unless NDEBUG was defined identically when compiling Ogre and when compiling client code, the class layouts won't match up and all sorts of bugs will ensue.

Firstly: Is this documented, and are there any other defines Ogre is sensitive to?

Secondly: Would it be worth having Ogre try to detect this on startup, and issue an error message?
al2950
OGRE Expert User
OGRE Expert User
Posts: 1227
Joined: Thu Dec 11, 2008 7:56 pm
Location: Bristol, UK
x 157

Re: #ifdef conditionals in header files

Post by al2950 »

The issue of NDEBUG has come up a couple times, I have not really taken any time to read any threads about it but you can find one here;
http://www.ogre3d.org/forums/viewtopic. ... 56#p513571

Also there is a TODO task in the Ogre 2.1 task list here;
https://trello.com/c/nXDj2OuM/44-fix-ab ... ot-defined
rogual
Gnoblar
Posts: 21
Joined: Sun Mar 01, 2015 9:33 pm
x 4

Re: #ifdef conditionals in header files

Post by rogual »

Thanks, looks like it's a known issue then!

If it's difficult to fix properly, we could at least have Ogre detect the bug, maybe?

It could be done by passing the value of NDEBUG into Ogre::Root::Root() using a default parameter, for example, then checking inside Ogre whether it's consistent. There might be a cleaner way, can't think of one right now.

That would at least stop people getting burned by this.
Post Reply