Missing something, runtime ex during TerrainManager creation

jaaku1111

22-02-2008 02:29:59

Hey Guys,

Ok so i'm trying to integrate ET (2.2) into my application. I've compiled the demo and it works great, so I put this code in my createScene in my own project:

ET::TerrainManager* mTerrainMgr;
ET::SplattingManager* mSplatMgr;
const ET::TerrainInfo* mTerrainInfo;


// create terrain manager
mTerrainMgr = new ET::TerrainManager(mSceneMgr);
mTerrainMgr->setLODErrorMargin(2, mCamera->getViewport()->getActualHeight());
mTerrainMgr->setUseLODMorphing(true, 0.2, "morphFactor");

int size = 193;

// create a fresh, mid-high terrain for editing
ET::TerrainInfo terrainInfo (size, size, vector<float>(size*size, 0.5f));
// set position and size of the terrain
terrainInfo.setExtents(AxisAlignedBox(0, 0, 0, 5000, 300, 5000));
// now render it
mTerrainMgr->createTerrain(terrainInfo);


(exact copy from my example code that works fine)

So when I try and run my application the debug shows its crashing with:
Unhandled exception at 0x7c812a5b in LoukiEngine.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012eb50..


at:

TerrainImpl::TerrainImpl(SceneManager* sceneMgr, const string& name)
: mSceneMgr(sceneMgr), mTerrainLoaded(false), mIndexHandler(0), mInstanceName(name),
mViewportHeight(0), maxLODAtBorders(false)
{
mOpt.maxPixelError = 3;
mOpt.useLODMorph = false;
mOpt.factorC = 0.0f;
}



I think its complaining about the mSceneMgr being invalid, but I know its not, because I can use it right above this... unless its getting messed up going into the ET class.

I'm sort of migrating into c++ from python/c# so I might have something simple wrong... anyone have any ideas?

SongOfTheWeave

22-02-2008 06:02:46

That's a bad pointer error.

It looks like mSceneMgr is not valid. I know you asserted that it was valid, but it looks like your computer says it isn't.

Are you sure you're passing the right pointer to the TerrainManager ctor?

jaaku1111

22-02-2008 12:29:27

I'm pretty sure... but like I said I'm newish to c++ so I might be doing it wrong?

I can post my full code if someone doesn't mind mucking through it. (i'll try and find a place I can post it this afternoon) or I can just email it directly.

thanks :)

CABAListic

22-02-2008 20:28:12

Hm, bad_alloc is, if I remember correctly, the exception which is thrown by new if it can't allocate the required memory. I've never seen this, the only case for this exception I know of is if you run out of memory - do you perchance have a misbehaving loop allocating endless amounts of memory or some such thing?

jaaku1111

23-02-2008 00:02:38

Ok, apparently I'm an idiot (and i hate c++...) in an experiment I tried pulling all the .cpp files into my project and just not doing the external linking (well that didn't work out) but when I undid it, and went back to importing the .lib file, it suddenly started working... O.o

So my guess is that I somehow was importing it right enough that it compiled, but wrong enough that it didn't run right. :)

Anyway, since I dragged you guys through helping me out, heres a link to what I'm working on. I'm aiming for a 'War3 meets Spellforce' type engine... all my friends love Hero based RTS maps, so I figured I'd shoot for something in that range.

http://louki.homeip.net (sorry its a slow connection)