Page 1 of 1

NULL pointer crash in OgreMain (1.9 version)

Posted: Fri May 27, 2016 8:27 am
by mageonline
Hi,

There is a null pointer crash in OgreMain.dll around 225000 iterations inside the g_scene->createEntity() call.

Is there a way to increase Ogre's memory pool?

Code: Select all

void createScene2()
{
	Entity * en;

	for (int i = 0; i < 500000; i++)
	{
		char t[100];

		sprintf(t, "ttn%d", i);

		Ogre::SceneNode * node = g_scene->getRootSceneNode()->createChildSceneNode(t, Ogre::Vector3(float16() * 1000, float16() * 1000, float16() * 1000));

		sprintf(t, "tte%d", i);

		en = g_scene->createEntity(t, "spade.mesh");
		if (en)
		{
			en->setQueryFlags(0);
			node->attachObject(en);
			node->setVisible(false);
		}
	}
}
OgreMovableObject.cpp - the crash is after the unchecked 'm'. Perhaps an "if (m == NULL) return m;" could be added in a hotfix 1.9 release?

Code: Select all

	MovableObject* MovableObjectFactory::createInstance(
		const String& name, SceneManager* manager, 
		const NameValuePairList* params)
	{
		MovableObject* m = createInstanceImpl(name, params);
		m->_notifyCreator(this);
		m->_notifyManager(manager);
		return m;
	}

Re: NULL pointer crash in OgreMain (1.9 version)

Posted: Fri May 27, 2016 2:41 pm
by frostbyte
not realy sure about c++ heap or mem stuff, but i guess that your bound to hit cpu/gpu memory ceiling at some point...
rather than increase memory( use 64bit compiler/buy new gpu/add memory ) i suggest you focus on lowering your app memory requirments
you can use Instancing for sharing the same vertics buffer between different entities( look at the Instancing demo on the Ogre sampleBrowser )
you can reduce your mesh polygon count( keywords: mesh Reduce, mesh lod, progressive mesh... demo on the ogre sampleBrowser )
you can unload/reload resources as neccessery at runtime( this is quite tricky... )
use different Lods in your app( best example is PagedGeometry plugin )...and so on( lot of other nasty tricks... )

Re: NULL pointer crash in OgreMain (1.9 version)

Posted: Mon May 30, 2016 5:52 pm
by dark_sylinc
frostbyte is right. At 225000 Entitys you're definitely going to start seeing memory problems.

The solution is to use the LARGEADRESSAWARE hack, or go full 64-bit. Or create less Entity (specially if they're static, consider combining their meshes). Using Ogre 2.x may also help since the memory footprint per Entity and per Node has been significantly reduced. But eventually you're always going to a hit a limit.

Re: NULL pointer crash in OgreMain (1.9 version)

Posted: Tue Jun 07, 2016 11:39 am
by mageonline
Thanks!

The /LARGEADDRESSAWARE linker flag was the quick and dirty solution for now :)

Re: NULL pointer crash in OgreMain (1.9 version)

Posted: Tue Jun 07, 2016 2:58 pm
by frostbyte
LARGEADRESSAWARE?
cons:
http://stackoverflow.com/questions/2288 ... xecutables
https://ogre3d.atlassian.net/browse/OGRE-178

don't forget its sort of a hack...so use it with caution...
you'll just need to test/debug an "above 2gb mem allocation scenerios"...

pros:
quick hack
there is an important advantage for the remaining 32bit users http://store.steampowered.com/hwsurvey
commercial software is shiped with this flag( no need for two versions ), so i guess it's ok if tested well...