Author Topic: Editor Freeze TNServerInstance.Start  (Read 7210 times)

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Editor Freeze TNServerInstance.Start
« on: February 22, 2017, 11:35:15 PM »
Everytime I use TNServerInstance.Start it freezes the Unity editor. It was working fine then it started happening randomly. Now it literally wont let me run a server in the editor. It works fine in builds. Any idea?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #1 on: February 23, 2017, 12:24:24 AM »
I've experienced Editor freezes a few times, I think some of the reasons were:
1. Scene contains an object with a TNObject with no ID set. These are meant to be instantiated at runtime.
2. Malformed packets. I've only experienced this when writing custom packets. I don't remember what the exact problem was or how I fixed it.
3. Entering playmode with a scene that expects TNManager to already be present and connected. This was a problem with my own code.

This was all in TNet 2, no idea if these issues apply to TNet 3, but it's something to look at at least.

I could also see a potential problem with RFCs being executed before the server instance fully initializes? Too lazy to check the code, but also something for you to look at.

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #2 on: February 23, 2017, 01:00:51 AM »
I've experienced Editor freezes a few times, I think some of the reasons were:
1. Scene contains an object with a TNObject with no ID set. These are meant to be instantiated at runtime.
2. Malformed packets. I've only experienced this when writing custom packets. I don't remember what the exact problem was or how I fixed it.
3. Entering playmode with a scene that expects TNManager to already be present and connected. This was a problem with my own code.

This was all in TNet 2, no idea if these issues apply to TNet 3, but it's something to look at at least.

I could also see a potential problem with RFCs being executed before the server instance fully initializes? Too lazy to check the code, but also something for you to look at.

1. The scene that contains the TNObjects don't even get loaded yet because it locks up before I try and connect to it. Therefore the scene is never loaded
2. I have no custom packets.
3. In TNet 3 I don't think it uses TNManager anymore. (I could be wrong)

And its not possible for RFCs to be called before the server initializes because no clients ever connect to it so I dont know who it'd be sending them too  ;D

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #3 on: February 23, 2017, 04:48:53 AM »
So after adding some logging inside of TNet it seems like the server is actually running. The "ThreadFunction" in TNGameServer.cs is running and is multi-threaded. But after about ~30 iterations of the for(;;) inside of "ThreadFunction" Unity locks up.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #4 on: February 23, 2017, 11:59:17 PM »
RFCs are executed locally.

Aside from the suggestions I already made I've got no clue. Perhaps try keeping the client single threaded (and the server instance embedded in the client).
Worst case scenario, you can set a breakpoint on ThreadFunction and step through until it locks up.
If you do figure it out, be sure to post it back here so we all benefit. Maybe it's something that can be fixed (or hardened) within TNet.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #5 on: February 24, 2017, 09:03:25 AM »
You can uncomment #define SINGLE_THREADED at the top of that file to force it into single threaded mode for debugging. That should make it possible for you to use MonoDevelop to break into the whatever loop is stuck and figure out what's going on. My guess is that you have an endless loop somewhere in your code, although I'm not sure why this only would happen in the editor and not in builds. Maybe something #if UNITY_EDITOR'd?

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #6 on: February 24, 2017, 10:17:13 PM »
So I've narrowed the issue down. As far as I can tell the issue happens when I don't define "fileName" in TNServerInstance.Start();

This code freezes my editor:
  1. int udpPort = Random.Range(10000, 40000);
  2. TNServerInstance.Start( port, udpPort, true);
  3.  

This code works perfectly:
  1. int udpPort = Random.Range(10000, 40000);
  2. TNServerInstance.Start( port, udpPort, "arena.dat" true);
  3.  

This may be some crazy issue with my system but to narrow it down even more I reinstalled Unity because I was getting frustrated, the issue still continues. Looks like its an issue on your side D:

Kuliu

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 16
    • View Profile
Re: Editor Freeze TNServerInstance.Start
« Reply #7 on: February 25, 2017, 03:04:34 AM »
Something didn't seem right, My entire OS was feeling sluggishly recently so I decided to format my HDD and reinstall Windows. After this all of my issues seem to have fixed. So my last post mostly is invalid as well as my issues. There might be an underlying issue with slow HDD read times and a server being started but I wouldn't worry about it too much.

Sorry for wasting your time D: