destroyResourceGroup behavior different between 1.7 and 1.11

Problems building or running the engine, queries about how to use features etc.
Post Reply
User avatar
EricB
Bronze Sponsor
Bronze Sponsor
Posts: 360
Joined: Fri Apr 09, 2010 5:28 am
Location: Florida
x 213
Contact:

destroyResourceGroup behavior different between 1.7 and 1.11

Post by EricB »

Ogre Version: 1.11.5 && 1.7.4
Operating System: All
Render System: OpenGL2 && DX9


I'm running into an issue that I haven't noticed in the past. My newer Ogre builds (64-bit version of the game, Ogre 1.11.5) doesn't clear old image resources after calling destroyResourceGroup. But on my older Ogre build (32-bit version, Ogre 1.7.4 and 1.8.1) it works as intended. The code dynamically loads a map logo based on what map the user selects. The game only loads the resource when the map is selected from the list.


I'm wondering if something was changed where I need another function call to clear caches or force clearing the resource group. Searched around, but didn't find anything. I guess I can diff Ogre code next, or simply just make sure all image files have unique names. The bigger issue is when end users are making their own maps.

I've simplified the code a bit so you gues don't have to float through a bunch of defines and stuff for multiple OS support.

Code: Select all

// Make Sure Resource Exists
 Ogre::StringVector  groups = Ogre::ResourceGroupManager::getSingletonPtr()->getResourceGroups();
 if(std::find(groups.begin(), groups.end(), "MenuMapView") != groups.end())
{
     Ogre::ResourceGroupManager::getSingletonPtr()->destroyResourceGroup("MenuMapView");
}

Ogre::ResourceGroupManager::getSingletonPtr()->createResourceGroup("MenuMapView");
		
//(*mapIT).first is a string containing the name of the game map's folder.
Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./media/Maps/"+(*mapIT).first,"FileSystem", "MenuMapView"); 
		
Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("MenuMapView");

//(*mapIT).second.picture filename of the logo picture for the selected map. All of them right now are "mapPicture.dds"
Image_MapSelector_MapPicture->setImage((*mapIT).second.picture);
EDIT: Added images, Left side, Ogre 1.11. Right side Ogre 1.7. Same maps selected in each image.
Image
Image
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by rpgplayerrobin »

I am using Ogre 1.11.2 and my resource groups looks something like this:

Code: Select all

Ogre::ResourceGroupManager& tmpResourceGroupManager = ResourceGroupManager::getSingleton();

string m_groupName = "TestResourceGroup";

// Create our resource group
tmpResourceGroupManager.createResourceGroup(m_groupName, true);

// Add resource locations needed
tmpResourceGroupManager.addResourceLocation("../Media/effects/textures/", "FileSystem", m_groupName);

// Initialise the resource group
tmpResourceGroupManager.initialiseResourceGroup(m_groupName);

// Check if we should not load the group dynamically
if(!tmpLoadDynamically) // tmpLoadDynamically is true if you want the resource group to only load assets when they are requested, most groups are used with tmpLoadDynamically as false
	// Load the resource group
	tmpResourceGroupManager.loadResourceGroup(m_groupName, true, true);
The difference between my code and yours is the "true" in the "createResourceGroup" function, as well as using "loadResourceGroup" for most groups.
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by rpgplayerrobin »

And by the way, I don't really know what kind of a class "Image_MapSelector_MapPicture" is, but if you are using a reference to a resource that was loaded in the resource group you destroyed, you might want to do something this before you destroy the resource group:
Image_MapSelector_MapPicture->setImage("white.png");

Otherwise the resource might not be able to be unloaded/destroyed when you use the "destroyResourceGroup" function.
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by loath »

i concur with rpgplayerrobin... i saw this when not releasing references so the resources were not released. i.e. a minor bug where i wasn't destroying nodes/entities prior to destroying the resource group and thus the refcounts were never decremented.
User avatar
EricB
Bronze Sponsor
Bronze Sponsor
Posts: 360
Joined: Fri Apr 09, 2010 5:28 am
Location: Florida
x 213
Contact:

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by EricB »

Thanks for the replies, and sorry for the late reply myself. I took a day off, which is rare for me.



I added the true bool for createResourceGroup's inGlobalPath I also added the loadResourceGroup function as well. Neither fixed the issue.

It's not having a problem loading a resource, it's just not overwriting the previous resource (even if it was destroyed) if it has the same filename.

I also thought of it being stuck in cache, and tried Image_MapSelector_MapPicture->setImage("blank.dds"); before applying the logo image again. Didn't work. I didn't do it before destroying the old resource group, which I have just tried, and sadly, it didn't work as well.


Image_MapSelector_MapPicture is a QuickGUI Image. Code for that is pretty simple: https://github.com/gearcity/VENT-QuickG ... e.cpp#L123

Basically just an Ogre::Image loaded via load.


I guess I could venture down to see if the resource is actually destroyed. But there is no conflicts according to the logs when I create a new resource group with the same name...

But ultimately, it doesn't matter. The map names themselves have to be unique, so an easy solution is just for me to have the map logo names be unique, and the easiest way to do that is to append the map's name to the map's logo file name. So I will edit my mod tools to do that.




That being said, looking at the log currently, I noticed something fishy. Right now for testing purposes, "Base City Map" and "Base Territories" use mapPicture.dds for their logos. "Classic Map" uses mapPicture_classicMap.dds for its logo.


14:39:34: Destroying resource group MenuMapView
14:39:34: Unloading resource group MenuMapView
14:39:34: Finished unloading resource group MenuMapView
14:39:34: Creating resource group MenuMapView
14:39:34: Added resource location './media/Maps/Base City Map' of type 'FileSystem' to resource group 'MenuMapView'
14:39:34: Initialising resource group MenuMapView
14:39:34: Parsing scripts for resource group MenuMapView
14:39:34: Finished parsing scripts for resource group MenuMapView
14:39:34: Creating resources for group MenuMapView
14:39:34: All done
14:39:34: Loading resource group 'MenuMapView' - Resources: 1 World Geometry: 1
14:39:34: Finished loading resource group MenuMapView

14:39:34: Texture: mapPicture.dds: Loading 1 faces(PF_A8R8G8B8,256x128x1) Internal format is PF_A8R8G8B8,256x128x1.

14:39:35: Destroying resource group MenuMapView
14:39:35: Unloading resource group MenuMapView
14:39:35: Finished unloading resource group MenuMapView
14:39:35: Creating resource group MenuMapView
14:39:35: Added resource location './media/Maps/Base Territories' of type 'FileSystem' to resource group 'MenuMapView'
14:39:35: Initialising resource group MenuMapView
14:39:35: Parsing scripts for resource group MenuMapView
14:39:35: Finished parsing scripts for resource group MenuMapView
14:39:35: Creating resources for group MenuMapView
14:39:35: All done

Texture should be loaded again here, but it's not. It is on Ogre 1.7 and 1.8 though...

14:39:35: Loading resource group 'MenuMapView' - Resources: 1 World Geometry: 1
14:39:35: Finished loading resource group MenuMapView
14:39:36: Destroying resource group MenuMapView
14:39:36: Unloading resource group MenuMapView
14:39:36: Finished unloading resource group MenuMapView
14:39:36: Creating resource group MenuMapView
14:39:36: Added resource location './media/Maps/Classic Map' of type 'FileSystem' to resource group 'MenuMapView'
14:39:36: Initialising resource group MenuMapView
14:39:36: Parsing scripts for resource group MenuMapView
14:39:36: Finished parsing scripts for resource group MenuMapView
14:39:36: Creating resources for group MenuMapView
14:39:36: All done
14:39:36: Loading resource group 'MenuMapView' - Resources: 1 World Geometry: 1
14:39:36: Finished loading resource group MenuMapView

14:39:36: Texture: mapPicture_classicMap.dds: Loading 1 faces(PF_A8R8G8B8,339x190x1) Internal format is PF_A8R8G8B8,339x190x1.

14:39:38: Leaving MenuState...
Image
User avatar
EricB
Bronze Sponsor
Bronze Sponsor
Posts: 360
Joined: Fri Apr 09, 2010 5:28 am
Location: Florida
x 213
Contact:

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by EricB »

So it looks from that, destroying the resource doesn't destroy the generated texture... So I will fiddle around down that path of releasing the resource and see if I can get it to work.
Image
loath
Platinum Sponsor
Platinum Sponsor
Posts: 290
Joined: Tue Jan 17, 2012 5:18 am
x 67

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by loath »

i'm on ogre 13.0 and in my "meshy" like tool i don't see the issue. i can load a mesh, see the texture loaded, and then reload the mesh which clears and re-initializes the texture.

so it could be a bug in 1.11 or perhaps a leaked resource.

ideas:
- create a fake resource group, load a texture into it, release the texture, destroy the resource group -- does this work as expected? (if not, bug in ogre, if yes leaked resource?)

- store a reference to the texture somewhere, destroy the resource group, and see what the reference count is on the texture. this is how i discovered my leak at the time.
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by rpgplayerrobin »

When checking the code for the QuickGUI Image, it seems strange.
This code loads the image into another resource group:

Code: Select all

Ogre::Image i;
i.load(mDesc->image_imageName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
That seems very wrong to me, as you want it in the other resource group you just tried to destroy/create.

If you fix that (by not letting QuickGUI Image load the texture that way) and the problem still exists, I would suggest you to do a very small one-function code that reproduces the problem, then we can look at it more in detail (and I could also debug what exactly happens).

You could test using the texture on an entity instead of a QuickGUI Image and see if the problem still happens.
If it works there, it may have something to do with the QuickGUI image.
Also make sure to set entity->getSubEntity(0)->setMaterialName("white") before destroying the resource group.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by paroj »

EricB wrote: Thu Oct 21, 2021 8:30 pm Image_MapSelector_MapPicture is a QuickGUI Image. Code for that is pretty simple: https://github.com/gearcity/VENT-QuickG ... e.cpp#L123
that code does not do anything. Ogre::Image is immediately destroyed after being loaded.
User avatar
EricB
Bronze Sponsor
Bronze Sponsor
Posts: 360
Joined: Fri Apr 09, 2010 5:28 am
Location: Florida
x 213
Contact:

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by EricB »

So, I can confirm that the resource is deleted, and loading of the image after deleting the resource will result in an exception being thrown.

If I load it into a QuickGUI Image, if I try to use it elsewhere, it's still the wrong image.

Delete the resource and try to use the image elsewhere, exception.

So the issue is probably the line rpgplayerrobin mentions or something deeper in QuickGUI. I don't think it's an issue with Ogre, It's just curious it works on older versions of Ogre, and not this one.

QuickGUI, the bane of my game. Since I'm the only person in the world still stuck with this lib, I'm not sure how much more time I will throw at it (especially since the game is already in Release Candidate phase). I will make a note to look into it further if my post-release crowd funding efforts allow me to update to the latest Ogre builds and get QuickGUI to work on all the newer renderers. I'll be doing a lot of work on the lib in that case and so I can address it then.


Thanks for the mindshare!
Image
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by paroj »

you might try OGRE_RESOURCEMANAGER_STRICT=0 when building ogre
User avatar
EricB
Bronze Sponsor
Bronze Sponsor
Posts: 360
Joined: Fri Apr 09, 2010 5:28 am
Location: Florida
x 213
Contact:

Re: destroyResourceGroup behavior different between 1.7 and 1.11

Post by EricB »

paroj wrote: Fri Oct 22, 2021 5:15 pm you might try OGRE_RESOURCEMANAGER_STRICT=0 when building ogre
I believe it's already set. But I will check again next time I am working on code... I've been in the technical/manual documentation phase for the last few weeks. :cry:
Image
Post Reply