Page 1 of 1

[Solved] 1.10 to 1.11 Paged Geometry upgrade

Posted: Sun Feb 03, 2019 4:02 am
by saintnick
Ogre Version: 1.11 :?:

Trying to upgrade the following code from 1.10 to 1.11. Ran into three problems.

1. Ogre manual calls for SharedPtr::operator unspecified_bool_type() instead.

Code: Select all

Ogre::MeshPtr &mesh;
if (mesh.isNull())
{
     // do stuff
}

//is the following correct?
if (!mesh)
{
	// do stuff
}
2. Ogre manual calls for Ogre::static_pointer_cast instead. Not sure how to replace staticCast with static_pointer_cast.

Code: Select all

			 m_ptrMaterial = Ogre::MaterialManager::getSingleton().getByName(mat, rg).staticCast<Ogre::Material>();
3. Ogre manual calls for getSubMeshes() instead. I changed SubMeshIterator to SubMeshList and use getSubMeshes. Not sure how replicate the behavior of iterator in the while statement. Is Make_Iterator correct?

Code: Select all

   Mesh::SubMeshIterator subMeshIterator = mesh->getSubMeshIterator();
   while (subMeshIterator.hasMoreElements()) {
      SubMesh *subMesh = subMeshIterator.getNext();
edit:
Building Paged Geometry I got these issues: https://github.com/OGRECave/ogre-caelum/issues/1. paroj posted: "you must use the install location/ install ogre first". How do I do this on windows?

Re: 1.10 to 1.11 upgrade

Posted: Tue Feb 05, 2019 8:21 pm
by loath
1.
isNull() still works.

2.

Code: Select all

auto material = Ogre::static_pointer_cast<Ogre::Material>(resource);  // resource is Ogre::ResourcePtr
3.

Code: Select all

auto submeshes = mesh->getSubMeshIterator ();
for (auto submesh = submeshes.begin (); submesh != submeshes.end (); ++submesh) { /* do work */ }
the code you posted looks fine though.

Re: 1.10 to 1.11 upgrade

Posted: Wed Feb 06, 2019 1:14 am
by paroj
3. @loath your suggestion still uses the deprecated getSubMeshIterator. A better replacement would be

Code: Select all

for(auto subMesh : mesh->getSubMeshes())
{
}

Re: 1.10 to 1.11 upgrade

Posted: Wed Feb 06, 2019 1:49 am
by loath
good to know. i will update, thanks!

Re: 1.10 to 1.11 upgrade

Posted: Wed Feb 06, 2019 2:10 pm
by saintnick
loath wrote: Tue Feb 05, 2019 8:21 pm 1.
isNull() still works.
Error C4996 'Ogre::SharedPtr<Ogre::Texture>::isNull': was declared deprecated

Ogre version 1.11.4. Notes say use SharedPtr::operator unspecified_bool_type().

Re: 1.10 to 1.11 upgrade

Posted: Thu Feb 07, 2019 3:52 am
by rpgplayerrobin
Yeah, I always get errors when using isNull, the first example you wrote is the correct one to avoid isNull with resource pointers.

Re: 1.10 to 1.11 upgrade

Posted: Thu Feb 07, 2019 3:20 pm
by saintnick
Thank you all for your help. I have fixed these compile errors and now when I try to run the code base the following shows up in Ogre.log:

Code: Select all

19:05:45: Added resource location '' of type 'FileSystem' to resource group 'Impostors'
19:05:45: Ogre::FileNotFoundException::FileNotFoundException: Cannot locate resource Impostor.HKSHDSOJOKUYFPGCRGINXONWCOTCIZTF.128.dds in resource group Impostors. in ResourceGroupManager::openResource at ogre-source\OgreMain\src\OgreResourceGroupManager.cpp (line 699)
19:05:45: Texture: Impostor.HKSHDSOJOKUYFPGCRGINXONWCOTCIZTF.128.png: Loading 1 faces(PF_A8B8G8R8,1024x512x1) with 10 hardware generated mipmaps from Image. Internal format is PF_A8B8G8R8,1024x512x1.
This is Example1 from the Paged Geometry add on. I have got Trees to show up after upgrading Paged Geometry to Ogre 1.11. However you can't get close to the trees before they disappear. I have included a video link of the behavior below.
http://www.mediafire.com/file/vf53b6yh ... M.mp4/file

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Thu Feb 07, 2019 8:05 pm
by loath
good to know saintnick... not sure why my isNull is compiling but i see now that it's deprecated and will fix it.

the main issue i had with upgrading to strict resourcing is not realizing all the places i was taking advantage of the automatic group resolution. for example, CreateEntity() is easy to misuse because the non-mesh-ptr versions make group assumptions and default to "General".

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Thu Feb 07, 2019 9:24 pm
by rpgplayerrobin
@saintnick

The error you see in the log is probably because of this code in the Paged Geometry addon:

Code: Select all

String fileNamePNG = "Impostor." + String(key, sizeof(key)) + '.' + StringConverter::toString(textureSize) + ".png";
String fileNameDDS = "Impostor." + String(key, sizeof(key)) + '.' + StringConverter::toString(textureSize) + ".dds";

//Attempt to load the pre-render file if allowed
needsRegen = force;
if (!needsRegen){
	try{
		texture = TextureManager::getSingleton().load(fileNameDDS, "Impostors", TEX_TYPE_2D, MIP_UNLIMITED);
	}
	catch (...){
		try{
			texture = TextureManager::getSingleton().load(fileNamePNG, "Impostors", TEX_TYPE_2D, MIP_UNLIMITED);
		}
		catch (...){
			needsRegen = true;
		}
	}
}
It seems to try to load the DDS texture first in the code as you may see. As I do not know how the system works I cannot help you solve it, but it should be possible to check if the resource exists or if the actual file exists before trying to load it.

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Thu Feb 07, 2019 11:41 pm
by saintnick
Thanks for the responses. I have solved the graphical bug and the plugin is working. Is forking pagedgeometry at OGRECave the best way to share this with the 1.11 community?

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Thu Feb 07, 2019 11:49 pm
by paroj
saintnick wrote: Thu Feb 07, 2019 11:41 pm Thanks for the responses. I have solved the graphical bug and the plugin is working. Is forking pagedgeometry at OGRECave the best way to share this with the 1.11 community?
yes, fork and create a pull request with your change

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Fri Feb 08, 2019 12:37 am
by saintnick
I have compiled my project using this 1.11 branch and can confirm it is working. https://github.com/Belsnickle/ogre-page ... /tree/1.11

When the application exits the following code crashes.

Code: Select all

void BatchedGeometry::clear()
{
   //Remove the batch from the scene
	if (m_pSceneNode)
	{
		m_pSceneNode->removeAllChildren();
		if (m_pSceneNode->getParent())
			m_pSceneNode->getParentSceneNode()->removeAndDestroyChild(m_pSceneNode);
		else
			m_pSceneMgr->destroySceneNode(m_pSceneNode);

		m_pSceneNode = 0;
	}
m_pSceneNode = 0; is the code that crashes on exit. Line 376 in BatchedGeometry.cpp. Can I just delete the line as the scene node was already destroyed?

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Fri Feb 08, 2019 12:54 am
by paroj
no, you should rather fix the code that accesses the nullptr without checking.

Also the pull-request should target the upstream repository, not your own. Use this link: https://github.com/OGRECave/ogre-pagedg ... ickle:1.11

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Fri Feb 08, 2019 12:59 am
by rpgplayerrobin
Nulling the pointer should not make it crash, are you sure it doesn't crash on the line before?

Anyway, I do null my own scene nodes when I am done destroying them, so it seems something else is going on with your crash.
I would never recommend using "removeAndDestroyChild", because that in turn also removes and destroys all of that nodes children.
If you then try to remove another scene node that was a child of that one, it will crash, and I think that is what has happened here.

Here is how I destroy scene nodes in my game, which has never had any issues:

Code: Select all

void Destroy(SceneNode* resource)
{
	// Destroy the node
	if (resource->getParent() != NULL)
		((SceneNode*)resource->getParent())->removeChild(resource);
	app->m_SceneManager->destroySceneNode(resource);
	resource = NULL;
}

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Fri Feb 08, 2019 2:01 am
by paroj
you are only nulling the pointer inside your destroy method which is pretty useless.

Also the whole method only does what destroySceneNode alone would do.

Re: 1.10 to 1.11 Paged Geometry upgrade

Posted: Fri Feb 08, 2019 2:21 am
by rpgplayerrobin
I was merely making a suggestion to change the way he would destroy the scene node, as something there seems to be off (since there was a crash).

But yeah, I will change my own function now. The nulling was probably a leftover from a "**" input I had a long time ago, but I did not know it removed the node from its parent.
You know how it is, having a code laying around for years without noticing it until now ("If it ain't broke, don't fix it").