[solved] Ogre Terrain Crashes on Save()

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
sambarrett1234
Gnoblar
Posts: 11
Joined: Sat Jul 05, 2014 4:43 pm

[solved] Ogre Terrain Crashes on Save()

Post by sambarrett1234 »

Hello,
I am writing a game engine using OGRE, and I've moved onto terrain. I have made the engine successfully load terrain, but for some reason it crashes whenever I call save() on a terrain. I have spent hours trying to fix it and I would appreciate any help :D In terms of multithreading, this code is executed in a different thread to the main game loop and it is not in the main thread - all 3 things are executed in different threads. Is that alright?

Here is my code for loading an area; first it checks to see if the terrain file already exists, then if not it creates a flat one.

(FYI ResourceManager and SceneManager are my own classes I've created, WorldName is a string, mCoordX and mCoordY are the x, y locations for the terrain.)

Code: Select all

mTerrainGroup.reset(new Ogre::TerrainGroup(SceneManager::mSceneMgr, Ogre::Terrain::ALIGN_X_Z, SceneManager::TERRAIN_SIZE, CELL_LENGTH));
mTerrainGroup->setFilenameConvention(ResourceManager::TERRAIN_DATA_FILE + WorldName + World::TERRAIN_ID_EXT, ResourceManager::TERRAIN_FILE_EXT);
mTerrainGroup->setOrigin(Ogre::Vector3::ZERO);

std::string filename = mTerrainGroup->generateFilename(mCoordX, mCoordY);
if(std::ifstream(filename).good()) //If the terrain file already exists...
{
	mTerrainGroup->defineTerrain(mCoordX, mCoordY);
}
else //Else create a blank one...
{
	mTerrainGroup->defineTerrain(mCoordX, mCoordY, 0.0f);
	mParentWorld->SetTextures(mTerrainGroup.get()); //Initialise the textures using those of the parent world (Ignore the mParentWorld bit, this function is basically initBlendMaps())
}
mTerrainGroup->loadAllTerrains();
if(!std::ifstream(filename))
{
mTerrainGroup->getTerrain(mCoordX, mCoordY)->save(filename);
}
mTerrainGroup->freeTemporaryResources();
Thanks in advance :D
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: Ogre Terrain Crashes on Save()

Post by loath »

unfortunately you have to call save() in the *main* thread -- you can't do graphics related operations in a worker thread in ogre terrain.

you can use worker threads to do other operations such as writing out your internal data structures.

hope that helps.
sambarrett1234
Gnoblar
Posts: 11
Joined: Sat Jul 05, 2014 4:43 pm

Re: Ogre Terrain Crashes on Save()

Post by sambarrett1234 »

It does help, thanks! :)
Post Reply