[SOLVED] Assertion during importTreeCollision

P_v

20-04-2006 02:48:07

I'm trying to import a Tree collision file that was exported using exportTreeCollision. While it's importing I can see that it calls the _newtonDeserializeCallback 3 times successfully, but on the fourth call it passes NULL for the buffer and a size of zero. This makes the call to ptr->read(buffer,size); turf with a NULL pointer assertion.

Anybody seen this or know what I might be doing wrong?

P_v

20-04-2006 17:41:52

if it helps, here is what I'm doing to load the collision tree:

TreeCollisionSerializer serial;
CollisionPrimitives::TreeCollision * coll = NULL;

ifstream f(".\\terrain.collision");
if (f.is_open())
{
DataStreamPtr ptr(new FileStreamDataStream(&f));

coll = new CollisionPrimitives::TreeCollision(m_pWorld);
serial.importTreeCollision(ptr, coll);

f.close();
} // if


The program is dying in TreeCollisionSerializer::_newtonDeserializeCallback at the ptr->read() line with buffer = NULL and size = 0.

void TreeCollisionSerializer::_newtonDeserializeCallback(void* deserializeHandle, void* buffer, size_t size)
{
Ogre::DataStreamPtr ptr=*(static_cast<Ogre::DataStreamPtr*>(deserializeHandle));
ptr->read(buffer,size);
}


My guess is that I'm doing something wrong with the DataStream. Any suggestions?

OvermindDL1

21-04-2006 01:45:19

I *think* that is a known problem that will be or is already fixed in latest cvs, will need to wait for walaber to comment on that though...

walaber

21-04-2006 07:19:25

hmmm... I haven't tested the serialization at all, another user submitted that. when I get a chance I will try and run some tests on it.

P_v

22-04-2006 02:19:00

I got it figured. Turns out ifstream opens in text mode by default (which is a pretty dumb default imho). I wasn't aware of that. The fix, therefore, is to open the file stream thusly:

ifstream f(".\\terrain.collision", ios::in | ios::binary);

And now everything works great! :D