Fix T39452: Meshes without materials causes a memory leak in the game engine

These types of meshes do not use material caching, and thus only the first created
material would be saved, but subsequent ones were not. Those subsequent materials
were then not being freed. Now we make sure to track all of the materials.

Note: Meshes that cannot make use of material caching (no materials or using face textures)
can still use up a large amount of RAM since a material is created per face.
This commit is contained in:
Mitchell Stokes 2014-03-27 13:46:22 -07:00
parent 84823220b8
commit 7ff123ce5c

@ -942,11 +942,12 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace
// this way only one KX_BlenderMaterial object has to exist per bucket
bool bucketCreated;
RAS_MaterialBucket* bucket = scene->FindBucket(polymat, bucketCreated);
if (bucketCreated) {
// this is needed to free up memory afterwards
converter->RegisterPolyMaterial(polymat);
converter->RegisterBlenderMaterial(bl_mat);
}
// this is needed to free up memory afterwards.
// the converter will also prevent duplicates from being registered,
// so just register everything.
converter->RegisterPolyMaterial(polymat);
converter->RegisterBlenderMaterial(bl_mat);
return bucket;
}