Skip to content

Commit 6c95c92

Browse files
committed
Fixed an error that internal processing was not possible when an exception occurred in OnConnected and OnClosed events.
Modified so that it can be easily viewed in Unity Console when logging Exception in UnityDebugLogger.
1 parent 62b745a commit 6c95c92

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

src/EuNet.Client/NetClient.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,33 @@ public void Close()
440440

441441
internal void OnSessionConnected()
442442
{
443-
State = SessionState.Connected;
444-
OnConnected?.Invoke();
443+
try
444+
{
445+
State = SessionState.Connected;
446+
OnConnected?.Invoke();
447+
}
448+
catch (Exception ex)
449+
{
450+
_logger.LogError(ex, ex.Message);
451+
}
445452
}
446453

447454
internal bool OnSessionClosed()
448455
{
449-
if (State != SessionState.Connected)
450-
return false;
456+
try
457+
{
458+
if (State != SessionState.Connected)
459+
return false;
451460

452-
State = SessionState.Closed;
453-
OnClosed?.Invoke();
461+
State = SessionState.Closed;
462+
463+
OnClosed?.Invoke();
464+
}
465+
catch(Exception ex)
466+
{
467+
_logger.LogError(ex, ex.Message);
468+
}
469+
454470
return true;
455471
}
456472

src/EuNet.Unity/Assets/Plugins/EuNet/Runtime/EuNet.Client/NetClient.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,33 @@ public void Close()
440440

441441
internal void OnSessionConnected()
442442
{
443-
State = SessionState.Connected;
444-
OnConnected?.Invoke();
443+
try
444+
{
445+
State = SessionState.Connected;
446+
OnConnected?.Invoke();
447+
}
448+
catch (Exception ex)
449+
{
450+
_logger.LogError(ex, ex.Message);
451+
}
445452
}
446453

447454
internal bool OnSessionClosed()
448455
{
449-
if (State != SessionState.Connected)
450-
return false;
456+
try
457+
{
458+
if (State != SessionState.Connected)
459+
return false;
451460

452-
State = SessionState.Closed;
453-
OnClosed?.Invoke();
461+
State = SessionState.Closed;
462+
463+
OnClosed?.Invoke();
464+
}
465+
catch(Exception ex)
466+
{
467+
_logger.LogError(ex, ex.Message);
468+
}
469+
454470
return true;
455471
}
456472

src/EuNet.Unity/Assets/Plugins/EuNet/Runtime/EuNet.Unity/Logger/UnityDebugLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public UnityDebugLogger()
1313

1414
public void LogError(Exception e, string msg)
1515
{
16-
Debug.LogError(msg);
16+
Debug.LogException(e);
1717
}
1818

1919
public void LogError(string msg)

0 commit comments

Comments
 (0)