diff options
author | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-05-15 15:50:46 +0300 |
---|---|---|
committer | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-05-15 15:54:38 +0300 |
commit | 2fa4a48bcef05671890fafc3fe50a8fa619f0259 (patch) | |
tree | c7bc28875ef0dfd444354e87353ceee2a7d6a182 /source/gameengine/Ketsji/KX_BlenderMaterial.cpp | |
parent | 7c06190882a1fa985d6e6998daa2db1f7577aed4 (diff) |
BGE: Fix T44700 mesh without material in blenderplayer.
If a mesh doesn't have a material we don't initialize the mSavedData in KX_BlenderMaterial to avoid crash.
Diffstat (limited to 'source/gameengine/Ketsji/KX_BlenderMaterial.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 93 |
1 files changed, 57 insertions, 36 deletions
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index 7ec2673bf1f..8e534ee1821 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -96,18 +96,20 @@ void KX_BlenderMaterial::Initialize( ); Material *ma = data->material; - // Save material data to restore on exit - mSavedData.r = ma->r; - mSavedData.g = ma->g; - mSavedData.b = ma->b; - mSavedData.a = ma->alpha; - mSavedData.specr = ma->specr; - mSavedData.specg = ma->specg; - mSavedData.specb = ma->specb; - mSavedData.spec = ma->spec; - mSavedData.ref = ma->ref; - mSavedData.hardness = ma->har; - mSavedData.emit = ma->emit; + if (ma) { + // Save material data to restore on exit + mSavedData.r = ma->r; + mSavedData.g = ma->g; + mSavedData.b = ma->b; + mSavedData.a = ma->alpha; + mSavedData.specr = ma->specr; + mSavedData.specg = ma->specg; + mSavedData.specb = ma->specb; + mSavedData.spec = ma->spec; + mSavedData.ref = ma->ref; + mSavedData.hardness = ma->har; + mSavedData.emit = ma->emit; + } mMaterial = data; mShader = 0; @@ -140,18 +142,21 @@ void KX_BlenderMaterial::Initialize( KX_BlenderMaterial::~KX_BlenderMaterial() { Material *ma = mMaterial->material; - // Restore Blender material data - ma->r = mSavedData.r; - ma->g = mSavedData.g; - ma->b = mSavedData.b; - ma->alpha = mSavedData.a; - ma->specr = mSavedData.specr; - ma->specg = mSavedData.specg; - ma->specb = mSavedData.specb; - ma->spec = mSavedData.spec; - ma->ref = mSavedData.ref; - ma->har = mSavedData.hardness; - ma->emit = mSavedData.emit; + + if (ma) { + // Restore Blender material data + ma->r = mSavedData.r; + ma->g = mSavedData.g; + ma->b = mSavedData.b; + ma->alpha = mSavedData.a; + ma->specr = mSavedData.specr; + ma->specg = mSavedData.specg; + ma->specb = mSavedData.specb; + ma->spec = mSavedData.spec; + ma->ref = mSavedData.ref; + ma->har = mSavedData.hardness; + ma->emit = mSavedData.emit; + } // cleanup work if (mConstructed) @@ -823,18 +828,34 @@ void KX_BlenderMaterial::UpdateIPO( { // only works one deep now - // GLSL Multitexture Input - mMaterial->material->specr = mMaterial->speccolor[0] = (float)(specrgb)[0]; - mMaterial->material->specg = mMaterial->speccolor[1] = (float)(specrgb)[1]; - mMaterial->material->specb = mMaterial->speccolor[2] = (float)(specrgb)[2]; - mMaterial->material->r = mMaterial->matcolor[0] = (float)(rgba[0]); - mMaterial->material->g = mMaterial->matcolor[1] = (float)(rgba[1]); - mMaterial->material->b = mMaterial->matcolor[2] = (float)(rgba[2]); - mMaterial->material->alpha = mMaterial->alpha = (float)(rgba[3]); - mMaterial->material->har = mMaterial->hard = (float)(hard); - mMaterial->material->emit = mMaterial->emit = (float)(emit); - mMaterial->material->spec = mMaterial->spec_f = (float)(spec); - mMaterial->material->ref = mMaterial->ref = (float)(ref); + // Multitexture Input + mMaterial->speccolor[0] = (float)(specrgb)[0]; + mMaterial->speccolor[1] = (float)(specrgb)[1]; + mMaterial->speccolor[2] = (float)(specrgb)[2]; + mMaterial->matcolor[0] = (float)(rgba[0]); + mMaterial->matcolor[1] = (float)(rgba[1]); + mMaterial->matcolor[2] = (float)(rgba[2]); + mMaterial->alpha = (float)(rgba[3]); + mMaterial->hard = (float)(hard); + mMaterial->emit = (float)(emit); + mMaterial->spec_f = (float)(spec); + mMaterial->ref = (float)(ref); + + Material *ma = mMaterial->material; + if (ma) { + // GLSL Input + ma->specr = (float)(specrgb)[0]; + ma->specg = (float)(specrgb)[1]; + ma->specb = (float)(specrgb)[2]; + ma->r = (float)(rgba[0]); + ma->g = (float)(rgba[1]); + ma->b = (float)(rgba[2]); + ma->alpha = (float)(rgba[3]); + ma->har = (float)(hard); + ma->emit = (float)(emit); + ma->spec = (float)(spec); + ma->ref = (float)(ref); + } } void KX_BlenderMaterial::Replace_IScene(SCA_IScene *val) |