heroiclabs / unity-sampleproject

A sample game called Pirate Panic for Unity engine built with Nakama server.
https://heroiclabs.com
Apache License 2.0
141 stars 41 forks source link

Sending Chat message causes a hard crash #9

Closed keiranlovett closed 3 years ago

keiranlovett commented 3 years ago

Using Unity Engine 2019.4.6f1, Nakama v2.0.7, and the Jan 7th version 04c9d9a. Only one user online during testing.

Problem

When sending a chat message the Unity editor hangs unexpectedly. There are no errors in Editor.log as this occurs making it a bit harder to debug.

Some testing has narrowed things to ChatManager.cs for line UnityMainThreadDispatcher.Instance().Enqueue(() => ReceiveMessage(message));

By removing UnityMainThreadDispatcher and simply using ReceiveMessage(message); you get a stackoverflow error. However I'm imagining this is for the purpose UnityMainThreadDispatcher was meant for. Happy to help provide any more context as needed.

novabyte commented 3 years ago

Thanks @keiranlovett we have a full refresh of this project in development which will be released in the next couple of weeks. I'll check in that rebuilt code whether the same bug exists.

keiranlovett commented 3 years ago

Thanks,

The reason we had identified it was using a similar structure for our own project.

Would you have any ideas for a more immediate fix or workaround until then that we could use?

Sent from my iPhone

On 18 Jan 2021, at 9:55 pm, Chris Molozian notifications@github.com wrote:

 Thanks @keiranlovett we have a full refresh of this project in development which will be released in the next couple of weeks. I'll check in that rebuilt code whether the same bug exists.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

keiranlovett commented 3 years ago

@novabyte upon more experimentation I've narrowed down what causes the crash.

Taking the example ChatManager.cs script and removing all content from the method ReceiveMessage (literally just a debug line included) and then by sending a message while subscribed to ReceivedChannelMessage like below

NakamaSessionManager.Instance.Socket.ReceivedChannelMessage += ReceiveMessage;

I get a stackoverflow.

HOWEVER

If I put the contents of ReceiveMessage in the ReceivedChannelMessage subscription like so:

 NakamaSessionManager.Instance.Socket.ReceivedChannelMessage += message =>
{
     ChatChannel channel;
     string messageContent = "";
     //Search for chat channel which should receive message, if it's not created - creates it
    ....
    ....
    ....
};

There is no stackoverflow and everything works as intended. So I believe it is a problem with the Socket implementation itself?

novabyte commented 3 years ago

@keiranlovett What version of the Unity client SDK do you use in your project?

This demo project runs an older version than what's recommended. It's part of the update work I mentioned we're in the middle of. In the meantime have a look at this chat example which is code only:

https://github.com/heroiclabs/nakama-unity/blob/master/Packages/Nakama/Editor/Snippets/RealtimeChatRoom.cs

keiranlovett commented 3 years ago

Proposing a closure based on the update you mentioned @novabyte and the chat example you have shared.

novabyte commented 3 years ago

@keiranlovett I'll make a note to close this issue as soon as we can open-source the refresh I mentioned to this demo project. 👍

novabyte commented 3 years ago

@keiranlovett The refresh to the project is now complete. I'll close this issue but have a look at this code and re-open if you still have issues.