Invalid memory usage when cloning material

Minor issues with the Ogre API that can be trivial to fix
Post Reply
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1002
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Invalid memory usage when cloning material

Post by Crashy »

If a loaded material is cloned, the memory size of the cloned material isn't tracked.

Quick example pseudo code:

Code: Select all

matA = MaterialManager::getSingleton().create(...); 
matA->load(); //adds xxx bytes to the ResourceManager::mMemoryUsage
matB = matA.clone(...); //adds nothing
matB->unload(); //removes xxx bytes from the ResourceManager::mMemoryUsage
matA->unload(); //removes xxx bytes from the ResourceManager::mMemoryUsage
If you do something like that, the ResourceManager::mMemoryUsage will be "negative", but it's an unsigned value so..
After that, every time ResourceManager::checkUsage(void) is called, it'll say the memory budget is exceeded.

Simple fix proposal, add this at the end of the Material::clone method

Code: Select all

//if we're cloning from a loaded material, notify the creator or otherwise tracked size won't be right
if (newMat->getLoadingState() == LOADSTATE_LOADED)
{
	// Notify manager
	if (mCreator)
		mCreator->_notifyResourceLoaded(newMat.get());
}
Follow la Moustache on Twitter or on Facebook
Image
paroj
OGRE Team Member
OGRE Team Member
Posts: 1794
Joined: Sun Mar 30, 2014 2:51 pm
x 939
Contact:

Re: Invalid memory usage when cloning material

Post by paroj »

can you create a pull-request?
Crashy
Google Summer of Code Student
Google Summer of Code Student
Posts: 1002
Joined: Wed Jan 08, 2003 9:15 pm
Location: Lyon, France
x 49
Contact:

Re: Invalid memory usage when cloning material

Post by Crashy »

Yup will do
Follow la Moustache on Twitter or on Facebook
Image
Post Reply