Handle exceptions in entity updates
This commit is contained in:
parent
8feefbbbbf
commit
b13c402170
@ -13,6 +13,7 @@ using System.Collections.Generic;
|
|||||||
using TrueCraft.Core.World;
|
using TrueCraft.Core.World;
|
||||||
using TrueCraft.API;
|
using TrueCraft.API;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using TrueCraft.API.Logging;
|
||||||
|
|
||||||
namespace TrueCraft
|
namespace TrueCraft
|
||||||
{
|
{
|
||||||
@ -154,8 +155,29 @@ namespace TrueCraft
|
|||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
PhysicsEngine.Update();
|
PhysicsEngine.Update();
|
||||||
var updates = Parallel.ForEach(Entities, e => e.Update(this));
|
try
|
||||||
|
{
|
||||||
|
lock (Entities)
|
||||||
|
{
|
||||||
|
var updates = Parallel.ForEach(Entities, e =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
e.Update(this);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
DespawnEntity(e);
|
||||||
|
Server.Log(LogCategory.Error, "Despawning entity {0} due to exception in update\n{1}", e.EntityID, ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
while (!updates.IsCompleted);
|
while (!updates.IsCompleted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
IEntity entity;
|
IEntity entity;
|
||||||
while (PendingDespawns.Count != 0)
|
while (PendingDespawns.Count != 0)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user