Can an event listener receive a null event?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
kveilleux
Posts: 1
Joined: 28 Jan 2016, 17:21

Can an event listener receive a null event?

Post by kveilleux »

As in the topic, I'm curious if an event listener can receive a null event and if that needs to be checked against for safety.

Code: Select all

void AddListeners()
{
   _sfClientInterface.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost);
}

private void OnConnectionLost(BaseEvent evt) 
{
    string reason = (string)evt.Params["reason"];
    Log(reason);

    <other logic here>
}
I am receiving some reports from other developers on the project that they seeing null exceptions in OnConnectionLost, and they believe that it is the BaseEvent "evt" that is null. I believe it may be the other code we have in the <other logic here> section, but I could not find anything on the documentation that specified whether or not the event coming into a function called from an EventListener was guaranteed to not be null. Is this the case? Or is the best practice to have an if (evt != null) safety check?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can an event listener receive a null event?

Post by Lapo »

No, events are always non null objects.
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply