BGE: Fixing a crash when animating objects with modifiers and armatures.
authorMitchell Stokes <mogurijin@gmail.com>
Wed, 9 Apr 2014 23:19:13 +0000 (16:19 -0700)
committerMitchell Stokes <mogurijin@gmail.com>
Wed, 9 Apr 2014 23:22:55 +0000 (16:22 -0700)
Our deformer system really needs some work. First, there was a crash
with shape keys because BL_ModifierDeformer derives from
BL_ShapeDeformer, which means we try to execute shape keys even if we do
not have them. Also, for some reason BL_ModifierDeformer::Update() does
not work if called from the threaded loop, so it is skipped for now. In
other words, skinned updates on meshes with modifiers are currently not
run in parallel.

source/gameengine/Converter/BL_ShapeDeformer.cpp
source/gameengine/Ketsji/KX_Scene.cpp

index 43f719d80c4363fe867f7f1e615f4838129665fc..8bb9f850bcf245981c926442e25b7fd7bdeb0381 100644 (file)
@@ -122,6 +122,12 @@ void BL_ShapeDeformer::ProcessReplica()
 
 bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject* parent)
 {
+       // Only load shape drivers if we have a key
+       if (GetKey() == NULL) {
+               m_useShapeDrivers = false;
+               return false;
+       }
+
        // Fix drivers since BL_ArmatureObject makes copies
        if (parent->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
                BL_ArmatureObject *arma = (BL_ArmatureObject*)parent;
index fbd9eeba8ed673472dbe961a80ab1bf6e1d5ef4c..e125dec860e4ec992c29c6708251aa97fe589c78 100644 (file)
@@ -1601,6 +1601,7 @@ void KX_Scene::AddAnimatedObject(CValue* gameobj)
 static void update_anim_thread_func(TaskPool *pool, void *taskdata, int UNUSED(threadid))
 {
        KX_GameObject *gameobj, *child;
+       RAS_Deformer *deformer;
        CListValue *children;
        bool needs_update;
        double curtime = *(double*)BLI_task_pool_userdata(pool);
@@ -1648,8 +1649,14 @@ static void update_anim_thread_func(TaskPool *pool, void *taskdata, int UNUSED(t
                for (int j=0; j<children->GetCount(); ++j) {
                        child = (KX_GameObject*)children->GetValue(j);
 
-                       if (child->GetDeformer())
+                       deformer = child->GetDeformer();
+
+                       // This check is ugly, but the modifier deformer currently doesn't
+                       // work if called from here. This is a quick work-around to prevent
+                       // crashing, but it really should be fixed.
+                       if (deformer && !dynamic_cast<BL_ModifierDeformer*>(deformer)) {
                                child->GetDeformer()->Update();
+                       }
                }
 
                children->Release();