Fix BGE bug in patch #8724 (memory optimization): serious problem with alpha texture...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sun, 4 May 2008 21:14:38 +0000 (21:14 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sun, 4 May 2008 21:14:38 +0000 (21:14 +0000)
source/gameengine/Ketsji/KX_BlenderMaterial.cpp
source/gameengine/Ketsji/KX_BlenderMaterial.h

index cfdcba8a5d67d90b95c16c83c4455fc25fd0e7fc..447275881065e85d73f18b40837fbfaacd327494 100644 (file)
@@ -84,6 +84,7 @@ KX_BlenderMaterial::KX_BlenderMaterial(
        mScene(scene),
        mUserDefBlend(0),
        mModified(0),
+       mConstructed(false),
        mPass(0)
 
 {
@@ -119,7 +120,9 @@ KX_BlenderMaterial::KX_BlenderMaterial(
 KX_BlenderMaterial::~KX_BlenderMaterial()
 {
        // cleanup work
-       OnExit();
+       if (mConstructed)
+               // clean only if material was actually used
+               OnExit();
 }
 
 
@@ -138,6 +141,10 @@ unsigned int* KX_BlenderMaterial::GetMCol(void) const
 
 void KX_BlenderMaterial::OnConstruction()
 {
+       if (mConstructed)
+               // when material are reused between objects
+               return;
+
        // for each unique material...
        int i;
        for(i=0; i<mMaterial->num_enabled; i++) {
@@ -148,19 +155,20 @@ void KX_BlenderMaterial::OnConstruction()
                        }
                        if(!mTextures[i].InitCubeMap(i, mMaterial->cubemap[i] ) )
                                spit("unable to initialize image("<<i<<") in "<< 
-                                               mMaterial->matname<< ", image will not be available");
+                                                mMaterial->matname<< ", image will not be available");
                } 
        
                else {
                        if( mMaterial->img[i] ) {
                                if( ! mTextures[i].InitFromImage(i, mMaterial->img[i], (mMaterial->flag[i] &MIPMAP)!=0 ))
                                        spit("unable to initialize image("<<i<<") in "<< 
-                                                mMaterial->matname<< ", image will not be available");
+                                               mMaterial->matname<< ", image will not be available");
                        }
                }
        }
        mBlendFunc[0] =0;
        mBlendFunc[1] =0;
+       mConstructed = true;
 }
 
 void KX_BlenderMaterial::OnExit()
index 2b1264154d0c5b7a094fc30d0b731784ea98ef67..b9d4819952011bbbb2f5730b627e1f525186417f 100644 (file)
@@ -93,6 +93,7 @@ private:
        bool                    mUserDefBlend;
        unsigned int    mBlendFunc[2];
        bool                    mModified;
+       bool                    mConstructed;                   // if false, don't clean on exit
 
        void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
        void ActivateTexGen( RAS_IRasterizer *ras ) const;