Creating a shape from a MemoryReadBuffer

NickM

12-01-2008 12:04:02

For my game I am updating a ConvexShape after it has been collided with in order to simulate damage deformation, I dont really want to keep creating a UserStream and reading from that, I'd rather be able to use a MemoryWriteBuffer/MemoryReadBuffer instead.

Has it been thought about, planned, dismissed before?
Is it something that was always going to be included in the future?
I could try to add it into NxOgre myself although I'll have to study it a fair bit first to work out whats going on. :cry: lol.

NickM

12-01-2008 14:57:01

I've added the necessary code to NxOgreShapeBlueprintConvex.h and .cpp but now I'm really out of my coding depth :?

I'm getting..

Windows has triggered a breakpoint in BangerRTG_d.exe.

This may be due to a corruption of the heap, and indicates a bug in BangerRTG_d.exe or any of the DLLs it has loaded.


It happens when the MemoryWriteBuffer destructor is called...

MemoryWriteBuffer::~MemoryWriteBuffer() {
if(data) {
NxGetPhysicsSDKAllocator()->free(data);
data = NULL;
}
}



The following then gets called from within NxOgreUserAllocator.h


void UserAllocator::free(void* memory)
{
// ::free(memory); return;

if(!memory)
{
printf("Warning: trying to free null pointer\n");
return;
}

#ifdef _DEBUG

#if USE_MUTEX
gMutex.Lock();
#endif
NxU32* ptr = ((NxU32*)memory)-6;
if(ptr[0]!=0xDeadBabe)
{
printf("Error: free unknown memory!!\n");
}
mNbAllocatedBytes -= ptr[1];
mNbAllocs--;

NxU32 MemBlockFirstFree = ptr[4];
NxU32 Line = ptr[3];
const char* File = (const char*)ptr[2];

// Remove the block from the Memory block list
if(mMemBlockList)
{
mMemBlockList[MemBlockFirstFree] = 0;
mMemBlockUsed--;
}

ptr[0]=0xDeadDead;
ptr[1]=0;
::free(ptr); <<<<<<<<<<<<<FAILING HERE

#if USE_MUTEX
gMutex.Unlock();
#endif

#else
NxU32* ptr = ((NxU32*)memory)-2;
if(ptr[0]!=0xDeadBabe)
{
printf("Error: free unknown memory!!\n");
}
mNbAllocatedBytes -= ptr[1];
if(mNbAllocatedBytes<0)
{
printf("Oops (%d)\n", ptr[1]);
}
mNbAllocs--;
ptr[0]=0xDeadDead;
ptr[1]=0;
::free(ptr);
#endif
}


it's failing on this line(as pointed to above)...

::free(ptr);

Here's the call stack after that line(whether thats any help or not I don't know)...

ntdll.dll!7c901230()
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!7c96c943()
ntdll.dll!7c96cd80()
ntdll.dll!7c960af8()
msvcr80d.dll!00620a94()
msvcr80d.dll!0061f02b()
kernel32.dll!7c85e7af()
msvcr80d.dll!005ecb0a()
msvcr80d.dll!005ebb21()
msvcr80d.dll!005ebb56()
msvcr80d.dll!005eba0e()
msvcr80d.dll!005eb98e()
> NxOgre_d.dll!NxOgre::UserAllocator::free(void * memory=0x0deb3eb8) Line 457 + 0xc bytes C++
NxOgre_d.dll!MemoryWriteBuffer::~MemoryWriteBuffer() Line 158 + 0x27 bytes C++



As I say, I'm well out of my coding depth now, I've posted this here, now I'll search the net and see what I can learn. :?

betajaen

12-01-2008 18:19:48

That's Ageia's code which I've copied from the samples. Try using my own UserAllocator, trouble is - it's in Bleeding.

http://svn.nxogre.org/branches/1.0/NxOg ... ocator.cpp
http://svn.nxogre.org/branches/1.0/NxOg ... llocator.h

The constructor on the Debug version may be a bit of a problem, you could remove that NxString and the mName parts. Then ignore the macro above it.

NickM

12-01-2008 20:07:47

Thanks, I'll try it when I get back home later. :)

NickM

13-01-2008 02:20:18

It works ok in release but after doing what you said for debug it works ok up until Ogre complains something about deleting memory that it doesn't own, it said the same thing when I replaced...

NxGetPhysicsSDKAllocator()->free(data);

with

Delete []data;

Anyway, I'll have another look at it tomorrow.

NickM

13-01-2008 10:41:59

Here's exactly what I'm getting.

The last part of the call stack...

> OgreMain_d.dll!Ogre::MemoryManager::dllocMem(const char * sourceFile=0x00c120b8, const unsigned int sourceLine=86, const char * sourceFunc=0x00c12148, const unsigned int deallocationType=8, const void * reportedAddress=0x0de620d8, const unsigned int processID=0) Line 1102 + 0xd bytes C++
NxOgre_d.dll!NxOgre::UserAllocator::free(void * memory=0x0de620d8) Line 86 + 0x31 bytes C++
NxOgre_d.dll!MemoryWriteBuffer::~MemoryWriteBuffer() Line 158 + 0x27 bytes C++


Ogre stops here...

// If you hit this assert, you tried to deallocate RAM that wasn't
// allocated by this memory manager.
m_assert(au != NULL);


I'll carry on investigating as I'm learning new things and understanding things a bit better as I go.

NickM

13-01-2008 10:50:54

I may have discovered the problem to be a programming mistake by me :evil: I'll investigate further.

NickM

13-01-2008 13:01:16

It wasn't what I thought it might be afterall, I'm still getting the same Ogre message and it's happening when I try to add the shape I've just created from the MemoryWriteBuffer.

Shape* Actor::addShape(ShapeBlueprint* sd) {


NxShapeIndex id = mCollisionModel.count();
sd->_bindToNxActor(this, id);
delete sd; <<<<<<Doesn't like this.
Shape* s = mCollisionModel.get(id);


return s;

}


Think I might give up on this for now, it's hurting my head. :cry: