Loading a resource on the fly

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Shem
Kobold
Posts: 39
Joined: Fri Feb 16, 2018 9:32 am
x 5

Loading a resource on the fly

Post by Shem »

Hi Guys,

I've recently started the process of upgrading my app to the latest version of Ogre -1.12.9 (from 1.10.11). I think I'm almost done but my dynamic resource loading stopped working. It use to be super simple:

Code: Select all

		m_rgmgr->declareResource(FilePath, "Texture", ResourceGroup);
		NewImage.load(FilePath, ResourceGroup);
I understand that having a blocking resource loading call is not the greatest way to go, but man, sometimes you just don't care right? Is there still a way to do that with the latest version?

Thanks in advance
Shem

loath
Platinum Sponsor
Platinum Sponsor
Posts: 178
Joined: Tue Jan 17, 2012 5:18 am
x 19

Re: Loading a resource on the fly

Post by loath »

i'm on 1.12.9 and i load every type of resource there is on the fly so the good news is it works.

what is failing and what is the error message?

you might need to trigger the load directly after declaring the resource:
auto& textures = Ogre::TextureManager::getSingleton ();
auto texture = textures.load (name, RESOURCE_GROUP);

Shem
Kobold
Posts: 39
Joined: Fri Feb 16, 2018 9:32 am
x 5

Re: Loading a resource on the fly

Post by Shem »

Thanks for the reply Loath,

The crash msg is:
!!!!Ogre::Exception!!!!Ogre::FileNotFoundException::FileNotFoundException: Cannot locate resource ...FILE_PATH\FILE_NAME.tga in resource group General. in ResourceGroupManager::openResource at OGRE_PATH\OgreMain\src\OgreResourceGroupManager.cpp (line 705)
If I'm not mistaken, your code:

Code: Select all

auto& textures = Ogre::TextureManager::getSingleton ();
auto texture = textures.load (name, RESOURCE_GROUP);
Assumes the resource is already part of the resource group while mine does not.

This use to work without issue on 1.10.11. There has to be a simple way to add a resource to a group on the fly and then load it to memory (Image in my case).

Thanks
Shem

Shem
Kobold
Posts: 39
Joined: Fri Feb 16, 2018 9:32 am
x 5

Re: Loading a resource on the fly

Post by Shem »

I think I fixed it by doing this:

Code: Select all

			m_rgmgr->addResourceLocation(path, "FileSystem", ResourceGroup, false);
			m_rgmgr->declareResource(file, "Texture", ResourceGroup);
			NewImage.load(file, ResourceGroup);
Also notice: file & path vs my original FilePath

Now, why are the fonts not loading...

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

Re: Loading a resource on the fly

Post by paroj »

after a resource group has been initialized, its index is fixed and no new resources can be added. See this for details:
https://ogrecave.github.io/ogre/api/lat ... ement.html

This was also the case with 1.10, but it would fall-back and scan the FileSystem after a miss in the index. You can get that behaviour back with OGRE_RESOURCEMANGER_STRICT=0.

The better solution would be to create a separate resource group for transient resources and delete/ re-create it as needed.

Shem
Kobold
Posts: 39
Joined: Fri Feb 16, 2018 9:32 am
x 5

Re: Loading a resource on the fly

Post by Shem »

Great! I'll try that.
Thank you Paroj

loath
Platinum Sponsor
Platinum Sponsor
Posts: 178
Joined: Tue Jan 17, 2012 5:18 am
x 19

Re: Loading a resource on the fly

Post by loath »

how did it go shem? i use paroj's technique for my mesh viewer tool. ( i kill the group everytime you load a new mesh )

Post Reply