Skip to content

Commit 750f78e

Browse files
committed
add logging to determine root cause of editor crash
1 parent c30c232 commit 750f78e

File tree

1 file changed

+59
-11
lines changed

1 file changed

+59
-11
lines changed

Intersect.Editor/Networking/PacketHandler.cs

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Intersect.Network;
1515
using Intersect.Network.Packets.Server;
1616
using Microsoft.Extensions.Logging;
17+
using ApplicationContext = Intersect.Core.ApplicationContext;
1718

1819
namespace Intersect.Editor.Networking;
1920

@@ -272,21 +273,68 @@ public void HandlePacket(IPacketSender packetSender, MapPacket packet)
272273
}
273274
}
274275

275-
if (Globals.CurrentMap.Id == packet.MapId && Globals.MapGrid != null && Globals.MapGrid.Loaded)
276+
if (Globals.CurrentMap is not { } currentMap)
276277
{
277-
for (var y = Globals.CurrentMap.MapGridY + 1; y >= Globals.CurrentMap.MapGridY - 1; y--)
278+
throw new InvalidOperationException(
279+
$"Received packet for map {packet.MapId} but the current map was null"
280+
);
281+
}
282+
283+
if (Globals.MapGrid is not { } mapGrid)
284+
{
285+
ApplicationContext.CurrentContext.Logger.LogError(
286+
"Received packet for map {MapId} before the map grid was initialized",
287+
packet.MapId
288+
);
289+
return;
290+
}
291+
292+
if (!mapGrid.Loaded)
293+
{
294+
ApplicationContext.CurrentContext.Logger.LogError(
295+
"Received packet for map {MapId} before the map grid was loaded",
296+
packet.MapId
297+
);
298+
return;
299+
}
300+
301+
if (currentMap.Id != packet.MapId)
302+
{
303+
ApplicationContext.CurrentContext.Logger.LogError(
304+
"Received packet for map {MapId} but the current map is {CurrentMapId} ({CurrentMapName})",
305+
packet.MapId,
306+
currentMap.Id,
307+
currentMap.Name
308+
);
309+
return;
310+
}
311+
312+
for (var y = currentMap.MapGridY + 1; y >= currentMap.MapGridY - 1; y--)
313+
{
314+
if (y < 0 || y >= mapGrid.GridHeight)
278315
{
279-
for (var x = Globals.CurrentMap.MapGridX - 1; x <= Globals.CurrentMap.MapGridX + 1; x++)
316+
continue;
317+
}
318+
319+
for (var x = currentMap.MapGridX - 1; x <= currentMap.MapGridX + 1; x++)
320+
{
321+
if (x < 0 || x >= mapGrid.GridWidth)
280322
{
281-
if (x >= 0 && x < Globals.MapGrid.GridWidth && y >= 0 && y < Globals.MapGrid.GridHeight)
282-
{
283-
var needMap = MapInstance.Get(Globals.MapGrid.Grid[x, y].MapId);
284-
if (needMap == null && Globals.MapGrid.Grid[x, y].MapId != Guid.Empty)
285-
{
286-
PacketSender.SendNeedMap(Globals.MapGrid.Grid[x, y].MapId);
287-
}
288-
}
323+
continue;
324+
}
325+
326+
var gridMapId = mapGrid.Grid[x, y].MapId;
327+
if (gridMapId == Guid.Empty)
328+
{
329+
continue;
330+
}
331+
332+
if (!MapInstance.TryGet(gridMapId, out _))
333+
{
334+
continue;
289335
}
336+
337+
PacketSender.SendNeedMap(gridMapId);
290338
}
291339
}
292340
}

0 commit comments

Comments
 (0)