[SOLVED] Crash in BatchedGeometry::SubBatch::build()

DragonL

26-01-2008 12:20:02

This plugin looks absolutely great, but I'm having trouble with it, so I hope someone here can help me out a little! :)

I set everything up pretty much like in the first tutorial (elected to use the addon code from cvs but compile it against the latest ogre sdk rather than ogre cvs), and it starts up just fine. It seems to work well while I just look at the forest from a distance, but if I move the camera in closer, it crashes. Stepping through the code reveals that the crash happens upon loading of a new page that comes into range.

This is what I do:


trees = new PagedGeometry(camera, 50);
trees->addDetailLevel<BatchPage>(400);
trees->addDetailLevel<ImpostorPage>(800, 100);
TreeLoader3D * treeLoader = new TreeLoader3D(trees, TBounds(0, 0, 1500, 1500));
trees->setPageLoader(treeLoader);

Entity * myTree = sceneMgr->createEntity("MyTree", "pine1.mesh");
for (int i = 0; i < 200; i++)
{
Radian yaw = Degree(Math::RangeRandom(0, 360));
Vector3 position;
position.x = Math::RangeRandom(0, 1500);
position.z = Math::RangeRandom(0, 1500);
position.y = 300;
Real scale = Math::RangeRandom(0.8f, 0.9f);
treeLoader->addTree(myTree, position, yaw, scale);
}


Here is where the crash happens (BatchedGeometry.cpp, line 360):


for (Ogre::ushort i = 0; i < vertBinding->getBufferCount(); ++i)
{
HardwareVertexBufferSharedPtr buffer = HardwareBufferManager::getSingleton()
.createVertexBuffer(vertDecl->getVertexSize(i), vertexData->vertexCount,
HardwareBuffer::HBU_STATIC_WRITE_ONLY);
vertBinding->setBinding(i, buffer);
vertexBuffers.push_back(static_cast<uchar*>(buffer->lock(HardwareBuffer::HBL_DISCARD)));
vertexBufferElements.push_back(vertDecl->findElementsBySource(i));
} // crash


When leaving the for scope, std::list::~list() is called, and so I get the error: "Invalid Address specified to RtlValidateHeap( 003F0000, 04CF70F0 )"

I'm thinking it must be the list returned by findElementsBySource, so I checked that function declaration, and I'm not sure if it's relevant, but it says this:


/** Gets a list of elements which use a given source.
@remarks
Note that the list of elements is returned by value therefore is separate from
the declaration as soon as this method returns.
*/
virtual VertexElementList findElementsBySource(unsigned short source);


I'm rather lost after trying to debug this for the past couple of hours, and I only just started using Ogre last week, so I hope one of you guys have an idea what might be wrong? :(

JohnJ

26-01-2008 17:44:43

I'm not sure what's wrong here, but I'm sure it's not your fault at least :). I'll try to replicate the problem and fix it.

JohnJ

26-01-2008 23:22:16

I tried placing the code you specified into World::load() of Example 1, and it seems to work fine, so while the problem doesn't seem to be in your setup code, something else must be causing the memory error.

I'm just guessing, but it's possible that you have a memory leak somewhere that's messing up allocations / deallocations. A while back I remember I was getting some "invalid heap" error in the most confusing places almost randomly, and it turned out that it was because I used "delete" instead of "delete[]" to deallocate an array.

DragonL

27-01-2008 00:03:52

Thank you for the quick replies JohnJ! :) I figured I'd better compile everything out of fresh cvs to make sure there were no interdepencies giving me problems, and after recompiling that and your plugin and then my own code I went over compiler settings and found what probably was the problem, because now it's working like a charm!

My own project was statically linked to the crt, while ogre was (I presume) dynamically linked... I'm ashamed to have led you on a wild goose chase for bugs when in fact it was my fault after all. :oops:

I'm very happy to have that beautiful forest up and running now though, and equally happy to find this forum so helpful! :D I'll do my best to contribute - keep up the brilliant work!