Memory Manager strangeness

Problems building or running the engine, queries about how to use features etc.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Memory Manager strangeness

Post by Kojack »

I've written a dll which links with ogre and provides various helper stuff to my main application. Recently, I enabled the ogre memory manager. It didn't like part of my code, saying I was deallocating memory with a different style to the way I allocated. But I'm not. I ended up writing a really simple test, which fails as well:

Code: Select all

void argh()
{
   int *ii = new int[1000];
   delete [] ii;
}
It asserts on the delete.
I've traced the execution as follows:
- new int[1000] calls operator new[] in newaop.cpp.
- operator new[] calls operator new in ogre's memory manager.
- delete [] calls ogre's version directly.
- memory manager sees that the memory was allocated with new and removed with delete [], and asserts.

newaop is part of vc which for some reason is inserting itself in so that it intercepts an array allocation and changes it into a non-array allocation.

I'm using VS.Net 2003. I've tried both ogre 0.15.1 and 0.15.2.

I tried putting the ogrenomemorymacros.h include just above the argh function, it made no difference (ogre memory manager still called for both, with the new [] still being converted by newaop.cpp).

There's no problem with that code if it's in my main application, it only freaks out when it's in a dll. And it's just a standard dll made with the project wizard, I haven't played with freaky settings or anything.

Anyone have any ideas what I'm doing wrong? Or how to disable the damn newaop.cpp from intercepting new []?
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 538

Post by Kojack »

Argh, I knew this would happen. I spent a day trying to get the thing to work, then fix it just minutes after posting about it here. :)
Oh well, it might help someone else with the same problem.

If my cpp doesn't include any ogre headers (I checked all the headers it includes, can't find any trace of ogre connected to the cpp). The ogre memory manager new and delete are called (with newaop getting in the way and wrecking it).

If my cpp includes OgreNoMemoryMacros.h, no change, ogre new and delete still called.

If my cpp includes OgreMemoryManager.h and OgreNoMemoryMacros.h, it all works perfectly. I never tried including OgreMemoryManager.h because I thought that it must have been included somewhere if the ogre new and delete are being used, and I was disabling it with OgreNoMemoryMacros.h anyway.


:)