Skip to content

Commit

Permalink
Bugfixes: Fix #83, NREs emitted due to ClientDisconnect jank
Browse files Browse the repository at this point in the history
ClientDisconnect seems to get called now when closing HostClient mode which originally set ClientState to Disconnecting... but in HostClient, the Client is not connected to the server so the main update loop tries to pump but gets null reference exceptions because some references are null (due to the reason it's not connected to the server). HostClients never connect to localhost themselves, they use a emulated connection. In theory, this patch should be fine, works with the latest Mirror Basic scene so uhh... I guess we're done here.
  • Loading branch information
SoftwareGuy committed Jan 17, 2022
1 parent 4bfd8e3 commit 05b34a9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions Assets/Mirror/Runtime/Transport/Ignorance/Ignorance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
// Copyright (c) 2019 - 2021 Matt Coburn (SoftwareGuy/Coburn64)
// Ignorance is licensed under the MIT license. Refer
// to the LICENSE file for more information.
using System;
using System.Collections.Generic;
using ENet;
using IgnoranceCore;
using Mirror;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace IgnoranceTransport
Expand Down Expand Up @@ -76,7 +76,7 @@ public override bool Available()
{
// Ignorance is not available for Unity WebGL, the PS4 (no dev kit to confirm) or Switch (port exists but I have no access to said code).
// Ignorance is available for most other operating systems.
#if (UNITY_WEBGL || UNITY_PS4 || UNITY_SWITCH)
#if UNITY_WEBGL || UNITY_PS4 || UNITY_SWITCH
return false;
#else
return true;
Expand All @@ -96,6 +96,8 @@ public override string ToString()

public override void ClientConnect(string address)
{
Debug.LogWarning("ClientConnect has been fired");

ClientState = ConnectionState.Connecting;
cachedConnectionAddress = address;

Expand Down Expand Up @@ -126,10 +128,15 @@ public override void ClientConnect(Uri uri)

public override void ClientDisconnect()
{
ClientState = ConnectionState.Disconnecting;

// 2022-01-17 Fix issue ticket #83
if (Client != null)
{
// Ugh this feels like a ugly hack
// If we're host client for example, we don't need to run these routines.
if (!Client.IsAlive) return;

ClientState = ConnectionState.Disconnecting;

// Fix for the Client commands RingBuffer not being initialized if we're in host mode.
if (Client.Commands != null)
Client.Commands.Enqueue(new IgnoranceCommandPacket { Type = IgnoranceCommandType.ClientWantsToStop });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public enum IgnoranceChannelTypes

public class IgnoranceInternals
{
public const string Version = "1.4.0r0 (LTS)";
public const string Version = "1.4.0r1 (LTS)";
public const string Scheme = "enet";
public const string BindAnyAddress = "::0";
}
Expand Down

0 comments on commit 05b34a9

Please sign in to comment.