Handling exceptions thrown at any point during coroutine update, not just at Coroutine.MoveNext, dirty workaround for a (rare?) pathfinding bug I haven't been able to reproduce

This commit is contained in:
Regalis
2016-07-21 21:20:21 +03:00
parent 8abea5c0c7
commit dd9b78f8ff
3 changed files with 37 additions and 30 deletions
@@ -346,6 +346,14 @@ namespace Barotrauma
{ {
finalPath.Add(pathNode.Waypoint); finalPath.Add(pathNode.Waypoint);
//there was one bug report that seems to have been caused by this loop never terminating:
//couldn't reproduce or figure out what caused it, but here's a workaround that prevents the game from crashing in case it happens again
if (finalPath.Count > nodes.Count)
{
DebugConsole.ThrowError("Pathfinding error: constructing final path failed");
return new SteeringPath(true);
}
path.Cost += pathNode.F; path.Cost += pathNode.F;
pathNode = pathNode.Parent; pathNode = pathNode.Parent;
} }
+24 -24
View File
@@ -65,42 +65,42 @@ namespace Barotrauma
for (int i = Coroutines.Count-1; i>=0; i--) for (int i = Coroutines.Count-1; i>=0; i--)
{ {
if (Coroutines[i].Coroutine.Current != null) try
{ {
WaitForSeconds wfs = Coroutines[i].Coroutine.Current as WaitForSeconds; if (Coroutines[i].Coroutine.Current != null)
if (wfs != null)
{ {
if (!wfs.CheckFinished(unscaledDeltaTime)) continue; WaitForSeconds wfs = Coroutines[i].Coroutine.Current as WaitForSeconds;
} if (wfs != null)
else
{
switch ((CoroutineStatus)Coroutines[i].Coroutine.Current)
{ {
case CoroutineStatus.Success: if (!wfs.CheckFinished(unscaledDeltaTime)) continue;
Coroutines.RemoveAt(i); }
continue; else
case CoroutineStatus.Failure: {
DebugConsole.ThrowError("Coroutine ''" + Coroutines[i]+ "'' has failed"); switch ((CoroutineStatus)Coroutines[i].Coroutine.Current)
break; {
case CoroutineStatus.Success:
Coroutines.RemoveAt(i);
continue;
case CoroutineStatus.Failure:
DebugConsole.ThrowError("Coroutine ''" + Coroutines[i]+ "'' has failed");
break;
}
} }
} }
Coroutines[i].Coroutine.MoveNext();
} }
//try catch (Exception e)
//{ {
Coroutines[i].Coroutine.MoveNext(); DebugConsole.ThrowError("Coroutine " + Coroutines[i].Name + " threw an exception: " + e.Message);
//}
//catch (Exception e)
//{
// DebugConsole.ThrowError("Coroutine " + Coroutines[i].Name + " threw an exception: " + e.Message);
//#if DEBUG //#if DEBUG
// throw e; // throw e;
//#endif //#endif
// Coroutines.RemoveAt(i); Coroutines.RemoveAt(i);
// } }
} }
} }
+5 -6
View File
@@ -318,18 +318,17 @@ namespace Barotrauma
if (leaveBehind) if (leaveBehind)
{ {
saveElement.Add(new XAttribute("location", Level.Loaded.Seed)); saveElement.SetAttributeValue("location", Level.Loaded.Seed);
saveElement.Add(new XAttribute("worldpos", ToolBox.Vector2ToString(sub.SubBody.Position))); saveElement.SetAttributeValue("worldpos", ToolBox.Vector2ToString(sub.SubBody.Position));
} }
else else
{ {
if (saveElement.Attribute("location") != null) saveElement.Attribute("location").Remove(); if (saveElement.Attribute("location") != null) saveElement.Attribute("location").Remove();
if (saveElement.Attribute("worldpos") != null) saveElement.Attribute("worldpos").Remove(); if (saveElement.Attribute("worldpos") != null) saveElement.Attribute("worldpos").Remove();
} }
if (saveElement.Attribute("pos") != null) saveElement.Attribute("pos").Remove(); saveElement.SetAttributeValue("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition));
saveElement.Add(new XAttribute("pos", ToolBox.Vector2ToString(Position - Submarine.HiddenSubPosition)));
} }