Browse Source

Added threaded update check to Zone & CollisionShape, as they do potentially non-threadsafe operations during OnMarkedDirty().

Lasse Öörni 13 years ago
parent
commit
aa237fd45a
2 changed files with 17 additions and 0 deletions
  1. 9 0
      Engine/Graphics/Zone.cpp
  2. 8 0
      Engine/Physics/CollisionShape.cpp

+ 9 - 0
Engine/Graphics/Zone.cpp

@@ -26,6 +26,7 @@
 #include "DebugRenderer.h"
 #include "DebugRenderer.h"
 #include "Node.h"
 #include "Node.h"
 #include "Octree.h"
 #include "Octree.h"
+#include "Scene.h"
 #include "XMLElement.h"
 #include "XMLElement.h"
 #include "Zone.h"
 #include "Zone.h"
 
 
@@ -195,6 +196,14 @@ bool Zone::IsInside(const Vector3& point) const
 
 
 void Zone::OnMarkedDirty(Node* node)
 void Zone::OnMarkedDirty(Node* node)
 {
 {
+    // Due to the octree query, is not safe from worker threads
+    Scene* scene = GetScene();
+    if (scene && scene->IsThreadedUpdate())
+    {
+        scene->DelayedMarkedDirty(this);
+        return;
+    }
+    
     Drawable::OnMarkedDirty(node);
     Drawable::OnMarkedDirty(node);
     
     
     // When marked dirty, clear the cached zone from all drawables inside the zone bounding box,
     // When marked dirty, clear the cached zone from all drawables inside the zone bounding box,

+ 8 - 0
Engine/Physics/CollisionShape.cpp

@@ -638,6 +638,14 @@ void CollisionShape::OnMarkedDirty(Node* node)
     Vector3 newWorldScale = node_->GetWorldScale();
     Vector3 newWorldScale = node_->GetWorldScale();
     if (!newWorldScale.Equals(cachedWorldScale_) && shape_)
     if (!newWorldScale.Equals(cachedWorldScale_) && shape_)
     {
     {
+        // Physics operations are not safe from worker threads
+        Scene* scene = GetScene();
+        if (scene && scene->IsThreadedUpdate())
+        {
+            scene->DelayedMarkedDirty(this);
+            return;
+        }
+        
         switch (shapeType_)
         switch (shapeType_)
         {
         {
         case SHAPE_BOX:
         case SHAPE_BOX: