[2.1] Memory corruption with debug builds

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
xissburg
Halfling
Posts: 83
Joined: Sun Feb 21, 2010 4:58 pm
x 28

[2.1] Memory corruption with debug builds

Post by xissburg »

I've had this problem for a while now but didn't want to spend more time getting frustrated trying to fix it. Release builds work fine. However when I build my app in debug mode and link with Ogre built in debug mode I get consistent memory corruption at certain points.

For example, it fails this assertion and so prints to the output "baseParams.mBlockType should always be BLOCK_MACRO! You can ignore this assert, but it usually indicates memory corruption (or you created the block without its default constructor)." If I remove the code that leads to this path it will crash here in OgreCompositorManager2 because the parameter definitionName gets corrupted and its mHash member variable is always turned into 0xffffffff.

I'm not sure these specific crashes are any relevant. This seems to be a much deeper problem which is certainly something stupid I did somewhere and I am just wondering if anybody ever had a similar issue and could share any hints.

This is only happening in my application. The samples built in debug mode work fine.

Thanks
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5298
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1] Memory corruption with debug builds

Post by dark_sylinc »

I think Ybalrid was having a similar issue not long ago.

The most likely culprit here is that OGRE_DEBUG_MODE is being defined differently between your app and Ogre.

If you're on Linux, compare your macros defined on build using "make VERBOSE=1".
If you're on Windows, compare your macros in MSVC in Properties Alt+F7 -> C/C++ -> Preprocessor -> Preprocessor Definitions.

Another very likely suspect is that the OgreBuildSettings.h file you're using to build is the wrong one for your Debug build.
xissburg
Halfling
Posts: 83
Joined: Sun Feb 21, 2010 4:58 pm
x 28

Re: [2.1] Memory corruption with debug builds

Post by xissburg »

OgreBuildSettings.h looks exactly the same in both debug and release builds. They have this on the top:

Code: Select all

#define OGRE_DEBUG_LEVEL_DEBUG 3
#define OGRE_DEBUG_LEVEL_RELEASE 0
Also make VERBOSE=1 is not printing any of these definitions or OGRE_DEBUG_MODE.
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5298
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: [2.1] Memory corruption with debug builds

Post by dark_sylinc »

Aha! I took a look at OgrePlatform.h and there is something that is behaving differently from what I remember:

Code: Select all

#if (defined(_DEBUG) || defined(DEBUG))
#   define OGRE_DEBUG_MODE OGRE_DEBUG_LEVEL_DEBUG
#else
#   define OGRE_DEBUG_MODE OGRE_DEBUG_LEVEL_RELEASE
#endif
If your Debug build does not define neither _DEBUG nor DEBUG, then you will follow the #define OGRE_DEBUG_MODE OGRE_DEBUG_LEVEL_RELEASE, not matching with Ogre

Another solution, instead of defining _DEBUG or DEBUG in your project, would be to set OGRE_DEBUG_LEVEL_DEBUG to 0 in CMake (not recommended since you'll lose some asserts and integrity checks, IdStrings won't have user-friendly readable strings, etc).
xissburg
Halfling
Posts: 83
Joined: Sun Feb 21, 2010 4:58 pm
x 28

Re: [2.1] Memory corruption with debug builds

Post by xissburg »

This related to this old recurring problem viewtopic.php?t=81356. I have defined DEBUG in my project and even printed OGRE_DEBUG_MODE which is now 3 and the problem persists.This is not making any sense. I am having these "Workspace definition ' ' not found" errors as well.
User avatar
areay
Bugbear
Posts: 819
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ
x 69

Re: [2.1] Memory corruption with debug builds

Post by areay »

xissburg wrote: Tue Aug 07, 2018 7:53 pm This related to this old recurring problem viewtopic.php?t=81356. I have defined DEBUG in my project and even printed OGRE_DEBUG_MODE which is now 3 and the problem persists.This is not making any sense. I am having these "Workspace definition ' ' not found" errors as well.
I recently had that exact problem and traced it down to having my compiled binary linked to both my release and debug ogre libraries. The problem was caused by having identically named cegui libraries for release and debug in my os' library search path and the release version of cegui depending on the release version of ogre. In my case, the search prefix for release version preceded the debug version so it grabbed that one first.

Took ages to figure that one out, only takes a few seconds to check using ldd or whatever the windows equivalent is. After I found the problem I switched round the order of library precedence fixing the problem permanently :roll: :roll: :roll:
Post Reply