SmartlyDressedGames / Legally-Distinct-Missile

Fork of Rocket for Unturned maintained by the game developers.
MIT License
79 stars 29 forks source link

Occasional NullReferenceException in `UnturnedPlayerEvents.InternalOnExperienceChanged` #43

Open aviadmini opened 3 years ago

aviadmini commented 3 years ago

Here: https://github.com/SmartlyDressedGames/Legally-Distinct-Missile/blob/master/Rocket.Unturned/Events/UnturnedPlayerEvents.cs#L206-L212

In some cases when a player connects and an OpenMod plugin modifies player experience UnturnedPlayerEvents.InternalOnExperienceChanged throws NRE. I suspect it's because an instance of UnturnedPlayerEvents component hasn't been attached to the player yet.

This could be fixed by adding a null check in the method but that's not a good solution because it would cause inconsistency in events.

SDGNelson commented 3 years ago

What do you propose?

aviadmini commented 3 years ago

Adding a null check and a warning about event not being processed by rocket component. It's debatably better than exceptions.

I currently do not know of a good solution. Somehow we'd need to ensure that rocket component UnturnedPlayerEvents gets attached before OpenMod events are fired. Maybe this is possible to do by reordering delegates in Provider.onServerConnected += OnPlayerConnected; ?

SDGNelson commented 3 years ago

Sorry for my delay. Maybe it should just silently check for null.

aviadmini commented 3 years ago

That doesn't solve the inconsistency issue. Ideally we want both openmod and rocketmod to assign their delegates before this event fires. So that neither of them misses it