Skip to content

Commit 626e0ea

Browse files
committed
add safety check for crash that Weylon encountered
1 parent 750f78e commit 626e0ea

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

Intersect.Client.Core/Entities/Entity.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -451,21 +451,28 @@ public virtual void Load(EntityPacket? packet)
451451
{
452452
if (Id == Globals.Me.Id)
453453
{
454-
if (Interface.Interface.GameUi == null)
455-
{
456-
ApplicationContext.Context.Value?.Logger.LogWarning($"'{nameof(Interface.Interface.GameUi)}' is null.");
457-
}
458-
else
459-
{
460-
if (Interface.Interface.GameUi.PlayerStatusWindow == null)
454+
Interface.Interface.EnqueueInGame(
455+
gameInterface =>
461456
{
462-
ApplicationContext.Context.Value?.Logger.LogWarning($"'{nameof(Interface.Interface.GameUi.PlayerStatusWindow)}' is null.");
463-
}
464-
else
465-
{
466-
Interface.Interface.GameUi.PlayerStatusWindow.ShouldUpdateStatuses = true;
467-
}
468-
}
457+
if (gameInterface.PlayerStatusWindow == null)
458+
{
459+
ApplicationContext.Context.Value?.Logger.LogWarning(
460+
$"'{nameof(gameInterface.PlayerStatusWindow)}' is null."
461+
);
462+
}
463+
else
464+
{
465+
gameInterface.PlayerStatusWindow.ShouldUpdateStatuses = true;
466+
}
467+
},
468+
(entityId, entityName) => ApplicationContext.CurrentContext.Logger.LogWarning(
469+
"Tried to load entity {EntityId} ({EntityName}) from packet before in-game UI was ready",
470+
entityId,
471+
entityName
472+
),
473+
packet.EntityId,
474+
packet.Name
475+
);
469476
}
470477
else if (Id != Guid.Empty && Id == Globals.Me.TargetId)
471478
{

Intersect.Client.Core/Interface/Interface.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ public static void EnqueueInGame(Action<GameInterface> action)
131131
PendingActionsForInGameInterface.Enqueue(() => action(GameUi));
132132
}
133133

134+
public static void EnqueueInGame<TArg0, TArg1>(Action<GameInterface> action, Action<TArg0, TArg1> onDeferred, TArg0 arg0, TArg1 arg1)
135+
{
136+
if (_uiInGame is {} uiInGame)
137+
{
138+
action(uiInGame);
139+
return;
140+
}
141+
142+
PendingActionsForInGameInterface.Enqueue(() => action(GameUi));
143+
onDeferred(arg0, arg1);
144+
}
145+
134146
public static Framework.Gwen.Control.Base? FindComponentUnderCursor(NodeFilter filters = default)
135147
{
136148
var cursor = new Point(InputHandler.MousePosition.X, InputHandler.MousePosition.Y);

0 commit comments

Comments
 (0)