[Solved] 1.10 to 1.11 Paged Geometry upgrade

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

[Solved] 1.10 to 1.11 Paged Geometry upgrade

Post 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?
Last edited by saintnick on Sun Feb 17, 2019 8:24 pm, edited 2 times in total.

loath
Platinum Sponsor
Platinum Sponsor
Posts: 150
Joined: Tue Jan 17, 2012 5:18 am
x 8

Re: 1.10 to 1.11 upgrade

Post 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.

paroj
OGRE Team Member
OGRE Team Member
Posts: 969
Joined: Sun Mar 30, 2014 2:51 pm
x 290
Contact:

Re: 1.10 to 1.11 upgrade

Post by paroj »

3. @loath your suggestion still uses the deprecated getSubMeshIterator. A better replacement would be

Code: Select all

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

loath
Platinum Sponsor
Platinum Sponsor
Posts: 150
Joined: Tue Jan 17, 2012 5:18 am
x 8

Re: 1.10 to 1.11 upgrade

Post by loath »

good to know. i will update, thanks!

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

Re: 1.10 to 1.11 upgrade

Post 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().

rpgplayerrobin
Gremlin
Posts: 151
Joined: Wed Mar 18, 2009 3:03 am
x 29

Re: 1.10 to 1.11 upgrade

Post 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.

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

Re: 1.10 to 1.11 upgrade

Post 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

loath
Platinum Sponsor
Platinum Sponsor
Posts: 150
Joined: Tue Jan 17, 2012 5:18 am
x 8

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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".

rpgplayerrobin
Gremlin
Posts: 151
Joined: Wed Mar 18, 2009 3:03 am
x 29

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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.

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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?

paroj
OGRE Team Member
OGRE Team Member
Posts: 969
Joined: Sun Mar 30, 2014 2:51 pm
x 290
Contact:

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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

User avatar
saintnick
Halfling
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 2

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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?

paroj
OGRE Team Member
OGRE Team Member
Posts: 969
Joined: Sun Mar 30, 2014 2:51 pm
x 290
Contact:

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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

rpgplayerrobin
Gremlin
Posts: 151
Joined: Wed Mar 18, 2009 3:03 am
x 29

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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;
}

paroj
OGRE Team Member
OGRE Team Member
Posts: 969
Joined: Sun Mar 30, 2014 2:51 pm
x 290
Contact:

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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.

rpgplayerrobin
Gremlin
Posts: 151
Joined: Wed Mar 18, 2009 3:03 am
x 29

Re: 1.10 to 1.11 Paged Geometry upgrade

Post 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").

Post Reply