Unity crashing hard on client side

I’ve managed to consistently crash unity. I’ve almost narrowed it down, but hopefully I’m just doing something stupid that someone can correct me on.

What I’m doing is OnPlayerConnected (in each object) sends a bunch of state information as RPCs to the player. It’s for stacks of chips (like in poker). I’m sending the state information instead of using buffered because after a while I expect chips to move in and out of stacks constantly, so instead once the player joins I’ll just initialize them with current stack state. Current stack state is a bunch of “AddChipToStack” calls. There is also the fact that stacks can disappear and be reformed as new stacks (if you empty the current stack it is destroyed)

The problem is that this crashes Unity. It always crashes, but not always at the same point.

I think one problem may have been related to Network.Destroy. But I have problems even if I remove Network.Destroy. In fact, even at the very beginning when I’ve just created the initial stacks without destroying any the client crashes. It looks like it sends the RPCs properly but then the client will crash. (I’m only testing with the Editor and Web… but it crashes in both places.) In the network debug, I can see before it crashes the client is sending it’s own network instantiate to create it’s camera/avatar and then immediately dies after.

If I reduce the number of chips down to a very small number 8 vs 80 total, then I have no problems. If I remove the “AddChipToStack” in the OnPlayerConnected, I also have no problem (although the client is then out of sync)… in fact once the player is connected I don’t think I have crashes (although I haven’t tested that thoroughly).

I want to think it has something to do with having too many RPCs coming in, or maybe a weird combination of Network.Instantiates and RPCs that is creating problems…

Any suggestions would be greatly appreciated.

Thanks!

Are the client and server parts the same project, like does one side have different scripts and RPC function names than the other side? That could cause undefined behavior. Is it possible network object setup is not complete when the function is called, like for example if a network object has not yet been instantiated or the network view not set up properly? To test that it might be simple to add a few second delay on the server after the client connects so he doesn’t send the RPC right in OnPlayerConnected but just calls a coroutine there which delays a bit first.

Whatever the cause of the problem, if you have narrowed it down to a small repro project it would be good to get it in a bug report, since Unity shouldn’t be crashing in any case (please email me the case number if you do).

Thanks for the reply. They are the same project with identical code (other than isServer/isClient stuff). Actually, the fact that it might not be fully instantiated on the client sounds very plausible. There’s a whole lot going on right at the startup… although thinking about it there were a few cases where a crash occurred later in the game…

For more information, I found a useful workaround in removing the initialization calls and replacing all the RPCs related to this particular group of objects to RPCMode.*Buffered. I have only seen one crash after playing for a long while and the client was able to relog in without a problem.

In any event, I’ll go back and replace the RPCs and put a delay behind OnPlayerConnected and post here on the result.

I’ve started working on stripping down the project as I kept getting the reminder to send a bug report to UT :)… I’ve got a lot of junk in this one as I’ve been experimenting, 300M in the project dir. :slight_smile: