From df9a774e5548139ec14def2d916733eb700325ec Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sun, 4 Dec 2022 15:28:49 +0000 Subject: [PATCH] Suppress exception from closed writer If writer is closed, the world is probably already cached. So just update its state and avatar count --- .../src/VirtualParadiseClient.NativeEvents.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/VpSharp/src/VirtualParadiseClient.NativeEvents.cs b/VpSharp/src/VirtualParadiseClient.NativeEvents.cs index fcf7441..b07bae5 100644 --- a/VpSharp/src/VirtualParadiseClient.NativeEvents.cs +++ b/VpSharp/src/VirtualParadiseClient.NativeEvents.cs @@ -277,20 +277,34 @@ public sealed partial class VirtualParadiseClient private async void OnWorldListNativeEvent(nint sender) { VirtualParadiseWorld world; - + string name; + int avatarCount; + WorldState state; + lock (Lock) { - string name = vp_string(sender, StringAttribute.WorldName); - int avatarCount = vp_int(sender, IntegerAttribute.WorldUsers); - var state = (WorldState)vp_int(sender, IntegerAttribute.WorldState); + name = vp_string(sender, StringAttribute.WorldName); + avatarCount = vp_int(sender, IntegerAttribute.WorldUsers); + state = (WorldState)vp_int(sender, IntegerAttribute.WorldState); world = new VirtualParadiseWorld(this, name) {AvatarCount = avatarCount, State = state}; _worlds[name] = world; } - if (_worldListChannel is not null) + try { - await _worldListChannel.Writer.WriteAsync(world).ConfigureAwait(false); + if (_worldListChannel is not null) + { + await _worldListChannel.Writer.WriteAsync(world).ConfigureAwait(false); + } + } + catch + { + if (_worlds.TryGetValue(name, out world!)) + { + world.AvatarCount = avatarCount; + world.State = state; + } } }