[2.1] Memory corruption with debug builds

Design / architecture / roadmap discussions related to future of Ogre3D (version 2.0 and above)
Post Reply
xissburg
Halfling
Posts: 52
Joined: Sun Feb 21, 2010 4:58 pm
x 2

[2.1] Memory corruption with debug builds

Post by xissburg » Mon Aug 06, 2018 3:54 am

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
0 x

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

Re: [2.1] Memory corruption with debug builds

Post by dark_sylinc » Mon Aug 06, 2018 4:29 pm

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.
0 x

xissburg
Halfling
Posts: 52
Joined: Sun Feb 21, 2010 4:58 pm
x 2

Re: [2.1] Memory corruption with debug builds

Post by xissburg » Mon Aug 06, 2018 9:52 pm

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.
0 x

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

Re: [2.1] Memory corruption with debug builds

Post by dark_sylinc » Mon Aug 06, 2018 11:17 pm

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).
0 x

xissburg
Halfling
Posts: 52
Joined: Sun Feb 21, 2010 4:58 pm
x 2

Re: [2.1] Memory corruption with debug builds

Post by xissburg » 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.
0 x

User avatar
areay
Bugbear
Posts: 818
Joined: Wed May 05, 2010 4:59 am
Location: Auckland, NZ

Re: [2.1] Memory corruption with debug builds

Post by areay » Mon Aug 13, 2018 2:47 am

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:
0 x

Post Reply