BoltEngine / Bolt-Tracker

New issue tracker for Photon Bolt
10 stars 2 forks source link

No null-check in BoltCore.BeginShutdown #147

Closed M1raclee closed 4 years ago

M1raclee commented 4 years ago

Describe the bug Got error: MissingReferenceException: The object of type '...' has been destroyed but you are still trying to access it. Need add null-check for entity before force destroy;

Stack BoltLog:Exception(Exception) Bolt.Entity:Detach() BoltCore:DestroyForce(Entity) BoltCore:BeginShutdown(ControlCommandShutdown) Bolt.ControlCommandShutdown:Run() Bolt.ControlBehaviour:Update()

Additional context

nlebedenco commented 4 years ago

So 1.2.10 BoltCore.Detach() is apparently using an Assert but it's still a problem. Let's say for example that I have an object that like BoltPoll calls ShutdownImmediate in OnDestroy. Then I close my application or press stop in the editor. Now because we can't control the order of destruction of game objects in unity (at least without resorting to tricks like explicit Script execution order) BoltEntity components may have been destroyed already by the time BoltCore.Detach is called. Best would be if Detach simply did nothing if passed a null entity.

BoltAssertFailedException: Assert Failed: 
Bolt.Exceptions.Assert.True (System.Boolean condition, System.String message) (at <91e633532a7e4582a260e897276e2d36>:0)
Bolt.Entity.Detach () (at <91e633532a7e4582a260e897276e2d36>:0)
BoltInternal.BoltCore.DestroyForce (Bolt.Entity entity) (at <91e633532a7e4582a260e897276e2d36>:0)
BoltInternal.BoltCore.ShutdownImmediate (UdpKit.UdpConnectionDisconnectReason disconnectReason) (at <91e633532a7e4582a260e897276e2d36>:0)
UnityEngine.Debug:LogException(Exception)
BoltLog:Exception(Exception)
BoltInternal.BoltCore:ShutdownImmediate(UdpConnectionDisconnectReason)
BoltNetwork:ShutdownImmediate()
Glass.Gameplay.Game:OnDestroy() (at Assets/Glass/Scripts/Behaviours/Gameplay/Game.cs:457)
nlebedenco commented 4 years ago

In fact, there is more to it than it seems. So I realized in my tests that the assertion was failing due to chaining of detachment of some entities. In other words, I was detaching an entity inside the Detached method of another entity and this poses a problem to ShutdownImmediate that calls destroy force on all entities in a loop expecting all to be properly attached.

ramonmelo commented 4 years ago

Thanks for your feedback!

Fixed on the next release.