[13.0] How to destroy all mygui-presenter material/widget

Problems building or running the engine, queries about how to use features etc.
Post Reply
benjm
Gnoblar
Posts: 2
Joined: Thu Sep 08, 2022 6:53 am
x 1

[13.0] How to destroy all mygui-presenter material/widget

Post by benjm »

Ogre Version: :?: 13.0
Operating System: :?: linux
Render System: :?:linux

Someone please help us to reduce the memory optimization of ogre objects!
We are now using orge on embedded system(linux), and the memory resource is very limited(gui only have 500M),
there are three mygui presenter, either of them own material and wiget(img), but we only need one presenter to be
showed on the screen, so the other can be destroyed. but how can we ultimately destroy all the material and widget resources,
Anyone have ideas about it?

Code: Select all

Ogre.log (optional)
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: [13.0] How to destroy all mygui-presenter material/widget

Post by rpgplayerrobin »

I think your post needs to be a bit more detailed to get anyone answering it correctly.

First of all, how do you measure the memory used by the GUI?
Do you know for sure that MyGUI is the culprit when it comes to memory? In that case, how? And what exactly in it is taking so much memory?

As I understand it, you have 3 separate screen, and you only want to show one at a time?
If that is the case, I don't see the other 2 screens as taking much resource at all, probably less than 500 bytes or so (because materials and their pointer to a texture takes very little memory), because you are still using the UI texture on the screen visible anyway.

benjm
Gnoblar
Posts: 2
Joined: Thu Sep 08, 2022 6:53 am
x 1

Re: [13.0] How to destroy all mygui-presenter material/widget

Post by benjm »

Thanks very much for your kind answer!

>First of all, how do you measure the memory used by the GUI?

Our UI process is based on MyGUI, so we simply calculate the total memory used by UI process with/without starting UI process.
We use "assignWidget" to bind with image resource, so we can also calculate the memory usage for specific presenter.

>Do you know for sure that MyGUI is the culprit when it comes to memory? In that case, how? And what exactly in it is taking so much memory?

Ram memory for our UI process is limited , and the image resource is about 30M(png,pixel is 1920*1080 for 3 presenter), when all image resources are loaded into memory, it costs too much memory.
We have to free the memory of not showing presenter when enter into one screen, the problem is we don't now how to delete all relative resources for
one presenter.
btw,the following is the function we used for free widget resources

int totalcnt=0, succcnt = 0;
ReleaseWidgetResource(mMainWidget, totalcnt, succcnt); // to free current present mMainWidget and its child-wigdet texture resource

Code: Select all

void ReleaseWidgetResource(MyGUI::Widget* widget, int &total_cnt, int &suc_cnt){
    int chil_cnt = 0;
    MyGUI::EnumeratorWidgetPtr childs = widget->getEnumerator();
    while (childs.next()){
        total_cnt++;
        chil_cnt++;

    MyGUI::ITexture* pRes = MyGUI::OgreRenderManager::getInstance().getTexture(childs.current()->_getTextureName());
    if(pRes != nullptr){
        suc_cnt++;
        if(setString.find(childs.current()->_getTextureName().c_str()) == setString.end()){
            MyGUI::OgreRenderManager::getInstance().destroyTexture(pRes);
            pRes = nullptr;
        }
        
        //MyGUI::OgreRenderManager::getInstance().destroyTexture(pRes);
    }

    //MyGUI::EnumeratorWidgetPtr ppchilds = childs->getEnumerator();
    ReleaseWidgetResource(childs.current(), total_cnt, suc_cnt);
}
}

>If that is the case, I don't see the other 2 screens as taking much resource at all, probably less than 500 bytes or so (because materials and their >pointer to a texture takes very little memory), because you are still using the UI texture on the screen visible anyway.

Yes, you are right, the pointer itself will not cost too much memory, but the resource it points to(material, widget) really cost too many memory,
and the memory after first bind with assignwidget/settexture will remain used status, this is the part that we want to free, we want to know is there
any existing function for us to free them, or other similar function like ReleaseWidgetResource we can use to free material objects and corresponding texture?

Last edited by benjm on Tue Sep 13, 2022 10:41 am, edited 1 time in total.
rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: [13.0] How to destroy all mygui-presenter material/widget

Post by rpgplayerrobin »

If you first remove it from the MyGUI system with your ReleaseWidgetResource code, you should be able to just unload the texture in Ogre directly after with something like this:

Code: Select all

// Destroys a resource
void Destroy(TexturePtr& resource)
{
	// Destroy the texture
	std::string tmpStr = resource->getName();
	TextureManager::getSingleton().unload(tmpStr);
	TextureManager::getSingleton().remove(tmpStr);
	resource.reset();

// Check if the texture still exists
if(TextureManager::getSingleton().resourceExists(tmpStr))
	// Show a message to the user
	ShowMessage("Destroy, The removal of a resource failed, the resource is still in use somewhere else.");
}

I am not sure about what you mean with the 3 presenters.
Are there 3 textures that is 1920*1080 in size? In that case it is pretty bad as textures should mostly follow the 2x rule (64, 128, 256, 512, 1024, 2048, etc).

I am not sure about how MyGUI works, but many GUI systems use an atlas texture to be able to batch everything together, so if you used an atlas texture there would be no need to ever unload it (like a 1024*1024 texture contain everything the UI needs to be able to render all UI in the entire game).
But I guess you are then using 3 different atlas textures for some reason? And you want to unload the ones that are not used.

For example, my game uses just one texture for all the UI in the entire game. That means that only one texture is used for 100+ different UI screens.

benjm
Gnoblar
Posts: 2
Joined: Thu Sep 08, 2022 6:53 am
x 1

Re: [13.0] How to destroy all mygui-presenter material/widget

Post by benjm »

Are there 3 textures that is 1920*1080 in size? In that case it is pretty bad as textures should mostly follow the 2x rule (64, 128, 256, 512, 1024, 2048, etc).

1920*1080 is the most largest pixel in one presenter, and there are also small pixels like(400*400 etc). One presenter has many widget which is bind with
large/small pixel images.
We now use ReleaseWidgetResource to free memory that is used by widget, here we want to know is there anyway to free memory used by material.

but many GUI systems use an atlas texture to be able to batch everything together, so if you used an atlas texture there would be no need to ever unload it (like a 1024*1024 texture contain everything the UI needs to be able to render all UI in the entire game).

What do you mean by "atals texture" here? do you mean the way we render one screen with multi pixel images mixtured into one texture? actually for one presenter, we have several screens to render responding to user's operation. Because we have 3 total presenters, we want to know the way to free all the resources of NOT showing presenter when enter into one presenter.

Thanks again for your kind response.

rpgplayerrobin
Gnoll
Posts: 619
Joined: Wed Mar 18, 2009 3:03 am
x 353

Re: [13.0] How to destroy all mygui-presenter material/widget

Post by rpgplayerrobin »

We now use ReleaseWidgetResource to free memory that is used by widget, here we want to know is there anyway to free memory used by material.

The code to unload a texture is in my previous post, you need to try that on the TexturePtr you want to unload to free its memory.
If it fails, then remove it from the MaterialPtr instance first as well (->setTextureName("white.png") or something like that to a texture you know exists and is very small and always loaded).

What do you mean by "atals texture" here? do you mean the way we render one screen with multi pixel images mixtured into one texture? actually for one presenter, we have several screens to render responding to user's operation. Because we have 3 total presenters, we want to know the way to free all the resources of NOT showing presenter when enter into one presenter.

There are a lot of material online regarding atlas textures, here are some:
https://en.wikipedia.org/wiki/Texture_atlas
https://gamedevelopment.tutsplus.com/ar ... -cms-26783

Post Reply