Browse Source

Fix crash in 15_Navigation.lua when adding and removing objects without having a path defined yet. Cleanup Navigation sample code.

Lasse Öörni 12 years ago
parent
commit
25a887cfe4

+ 5 - 3
Bin/Data/LuaScripts/15_Navigation.lua

@@ -227,9 +227,7 @@ function SetPathPoint()
             endPosDefined = true
             endPosDefined = true
         end
         end
         
         
-        if startPosDefined and endPosDefined then
-            RecalculatePath()
-        end
+        RecalculatePath()
     end
     end
 end
 end
 
 
@@ -271,6 +269,10 @@ function CreateMushroom(pos)
 end
 end
 
 
 function RecalculatePath()
 function RecalculatePath()
+    if not startPosDefined or not endPosDefined then
+        return
+    end
+
     local navMesh = scene_:GetComponent("NavigationMesh")
     local navMesh = scene_:GetComponent("NavigationMesh")
     currentPath = navMesh:FindPath(startPos, endPos)
     currentPath = navMesh:FindPath(startPos, endPos)
 end
 end

+ 4 - 2
Bin/Data/Scripts/15_Navigation.as

@@ -228,8 +228,7 @@ void SetPathPoint()
             endPosDefined = true;
             endPosDefined = true;
         }
         }
         
         
-        if (startPosDefined && endPosDefined)
-            RecalculatePath();
+        RecalculatePath();
     }
     }
 }
 }
 
 
@@ -281,6 +280,9 @@ Node@ CreateMushroom(const Vector3& pos)
 
 
 void RecalculatePath()
 void RecalculatePath()
 {
 {
+    if (!startPosDefined || !endPosDefined)
+        return;
+
     NavigationMesh@ navMesh = scene_.GetComponent("NavigationMesh");
     NavigationMesh@ navMesh = scene_.GetComponent("NavigationMesh");
     currentPath = navMesh.FindPath(startPos, endPos);
     currentPath = navMesh.FindPath(startPos, endPos);
 }
 }

+ 4 - 2
Source/Samples/15_Navigation/Navigation.cpp

@@ -278,8 +278,7 @@ void Navigation::SetPathPoint()
             endPosDefined_ = true;
             endPosDefined_ = true;
         }
         }
         
         
-        if (startPosDefined_ && endPosDefined_)
-            RecalculatePath();
+        RecalculatePath();
     }
     }
 }
 }
 
 
@@ -331,6 +330,9 @@ Node* Navigation::CreateMushroom(const Vector3& pos)
 
 
 void Navigation::RecalculatePath()
 void Navigation::RecalculatePath()
 {
 {
+    if (!startPosDefined_ || !endPosDefined_)
+        return;
+    
     NavigationMesh* navMesh = scene_->GetComponent<NavigationMesh>();
     NavigationMesh* navMesh = scene_->GetComponent<NavigationMesh>();
     navMesh->FindPath(currentPath_, startPos_, endPos_);
     navMesh->FindPath(currentPath_, startPos_, endPos_);
 }
 }