Problems with terrain [Solved]

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Problems with terrain [Solved]

Post by lonewolff »

Hi guys,

I have a problem with a terrain (using code from the tutorial on the wiki) on 1.9 static linked.

It runs fine in the IDE (VS.net 2010) in release mode but crashes when running from the executable ("application has stopped working").

This is the last thing the log file says. So, it doesn't really help in this case.
09:47:16: Terrain created; size=513 minBatch=33 maxBatch=65 treeDepth=4 lodLevels=5 leafLods=2
09:47:26: Texture: dirt256.jpg: Loading 1 faces(PF_R8G8B8,256x256x1) Internal format is PF_X8R8G8B8,256x256x1.
09:47:26: Texture: dirt04.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) Internal format is PF_X8R8G8B8,512x512x1.
09:47:26: Texture: adirt20.jpg: Loading 1 faces(PF_R8G8B8,512x512x1) Internal format is PF_X8R8G8B8,512x512x1.
My whole application is in-line while I get this sorted out (before I break it up and place into my main app).

This is the terrain generation section before the main loop is entered.

Code: Select all

	// Terrain global options	
	TerrainGlobalOptions* mTerrainGlobals=new TerrainGlobalOptions();
	mTerrainGlobals->setMaxPixelError(8);
    mTerrainGlobals->setCompositeMapDistance(3000);
    mTerrainGlobals->setLightMapDirection(light->getDerivedDirection());
    mTerrainGlobals->setCompositeMapAmbient(mSceneMgr->getAmbientLight());
    mTerrainGlobals->setCompositeMapDiffuse(light->getDiffuseColour());

	// Terrain group
 	TerrainGroup* mTerrainGroup=new TerrainGroup(mSceneMgr,Ogre::Terrain::ALIGN_X_Z,513,1000.0f);
	mTerrainGroup->setFilenameConvention(String("BasicTutorial3Terrain"),String("dat"));
	mTerrainGroup->setOrigin(Vector3::ZERO);
 
    // Configure default import settings for if we use imported image
    Terrain::ImportData& defaultimp=mTerrainGroup->getDefaultImportSettings();
    defaultimp.terrainSize=2049;
    defaultimp.worldSize=1000.0f;
    defaultimp.inputScale=100;
    defaultimp.minBatchSize=33;
    defaultimp.maxBatchSize=65;
    
	// textures
    defaultimp.layerList.resize(3);
    defaultimp.layerList[0].worldSize=50;
    defaultimp.layerList[0].textureNames.push_back("dirt256.jpg");
    defaultimp.layerList[1].worldSize=100;
    defaultimp.layerList[1].textureNames.push_back("dirt04.jpg");
    defaultimp.layerList[2].worldSize=200;
    defaultimp.layerList[2].textureNames.push_back("adirt20.jpg");

	for(long x=0;x<=0;++x)
	{
		for(long y=0;y<=0;++y)
		{
			String filename=mTerrainGroup->generateFilename(x,y);
			if(ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(),filename))
				mTerrainGroup->defineTerrain(x,y);
			else
			{
				Image img;
				img.load("terrain.png",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
				if(x%2!=0)
					img.flipAroundY();
				if(y%2!=0)
					img.flipAroundX(); 

				mTerrainGroup->defineTerrain(x,y,&img);
			}
		}
	}
 
	mTerrainGroup->loadAllTerrains(true);

	TerrainGroup::TerrainIterator ti=mTerrainGroup->getTerrainIterator();
	while(ti.hasMoreElements())
	{
		Terrain* terrain=ti.getNext()->instance;
		TerrainLayerBlendMap* blendMap0=terrain->getLayerBlendMap(1);
		TerrainLayerBlendMap* blendMap1=terrain->getLayerBlendMap(2);
		Real minHeight0=70;
		Real fadeDist0=40;
		Real minHeight1=70;
		Real fadeDist1=15;
		float* pBlend1=blendMap1->getBlendPointer();
		for(uint16 y=0;y<terrain->getLayerBlendMapSize();++y)
		{
			for(uint16 x=0;x<terrain->getLayerBlendMapSize();++x)
			{
				Real tx,ty;
 				blendMap0->convertImageToTerrainSpace(x,y,&tx,&ty);
				Real height=terrain->getHeightAtTerrainPosition(tx,ty);
				Real val=(height-minHeight0)/fadeDist0;
				val=Math::Clamp(val,(Real)0,(Real)1);
 
				val=(height-minHeight1)/fadeDist1;
				val=Math::Clamp(val,(Real)0,(Real)1);
				*pBlend1++=val;
			}
		}
		blendMap0->dirty();
		blendMap1->dirty();
		blendMap0->update();
		blendMap1->update();
	}

	mTerrainGroup->freeTemporaryResources();
Any advice would be absolutely awesome! :D


[edit]
Some futher debugging reveals that the application crashes on mTerrainGroup->loadAllTerrains(true);

Also found that using the same assets as used in the tutorial (http://www.ogre3d.org/tikiwiki/tiki-ind ... =Tutorials) is causing a stack overflow. So, I am somewhat confused :(
Last edited by lonewolff on Mon Jul 28, 2014 3:29 am, edited 1 time in total.
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Problems with terrain

Post by lonewolff »

Hmmm, looks like there is a problem with the way my Static 1.9 Ogre Source compiled.

Running it with the 1.9 SDK works fine.

With my static source, every compilation complains about FreeImage - something about a destination being too small. So, it looks like that warning has finally come back to bite me.

Back to re-compiling the original source - LOL :)
Mikz
Gnoblar
Posts: 5
Joined: Tue Dec 16, 2014 8:47 pm

Re: Problems with terrain [Solved]

Post by Mikz »

I'm having the same issue, but not with static build but with the dynamic one.
Windows 7 Home x64
Ogre SDK 1.9 built with MinGW + CMake using this guide: http://www.ogre3d.org/tikiwiki/tiki-ind ... +and+MinGW, but WITHOUT boost (didn't want to wait for that long since boost is optional)!
Source copied 1 to 1 from "full source" at the end of an "Basic Tutorial 3"
Application crashes with annoying "program has stopped working" window on both "Release" and "Debug"
When I comment-out all code in createScene method from "mTerrainGroup->loadAllTerrains(true);" to the end of the method, everything runs fine (of course nothing but fps counter can be seen).

But what's worst of all: if I'll try to run the application using Code::Blocks Debugger (gdb) it runs fine and everything is working so I can't even locate the cause of the error.
User avatar
lonewolff
Ogre Magi
Posts: 1207
Joined: Wed Dec 28, 2005 12:58 am
x 6

Re: Problems with terrain [Solved]

Post by lonewolff »

In my case, I had to download a newer version of the freeimage source.
Mikz
Gnoblar
Posts: 5
Joined: Tue Dec 16, 2014 8:47 pm

Re: Problems with terrain [Solved]

Post by Mikz »

Hi, thanks for your reply!
By "newer" you mean 3.16? Isn't 3.15 sufficient (that's the one I've got from cabalistic ogre deps)?

For now I'm building ogre 1.9 dd09c099cab4 (previous one was older, taken from 1.9 tag, not branch) with boost. Building boost took four hours but it's done and now I'm waiting for Ogre Release to build (49% :D). After it's done, I'll try again, maybe it will run. If not, I'll update FreeImage and rebuild Ogre.

edit: After compiling new Ogre everything works (well, almost everything: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=82354 but that's out of scope ;) ) so the reason was either lacking boost or old Ogre version (previously I was using one tagged as 1.9 on bitbucket). I'll try to figure it out in few days and post some information about it here.

lonewolff: I'm still intrested in FreeImage version you've got.
Post Reply