BoltEngine / Bolt-Tracker

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

`BoltNetwork.RemoveGlobalEventCallback` does not remove callbacks #170

Closed heilhead closed 4 years ago

heilhead commented 4 years ago

Describe the bug Apologies for sticking my nose into your code, but I'm having a problem where BoltNetwork.RemoveGlobalEventCallback<T>(Action<T> callback) would not find the callback and throw a warning Could not find delegate registered as callback.

I believe the problem is in the if (!this._callbacks.TryGetValue(typeof (T), out callbackWrapperList)) line of the following function (EventDispatcher.Remove):

    public void Remove<T>(Action<T> callback) where T : Event
    {
      List<EventDispatcher.CallbackWrapper> callbackWrapperList;
      if (!this._callbacks.TryGetValue(typeof (T), out callbackWrapperList))
      {
        for (int index = 0; index < callbackWrapperList.Count; ++index)
        {
          if ((Delegate) callbackWrapperList[index].Original == (Delegate) callback)
          {
            callbackWrapperList.RemoveAt(index);
            return;
          }
        }
      }
      BoltLog.Warn("Could not find delegate registered as callback");
    }

To Reproduce Steps to reproduce the behavior:

BoltNetwork.AddGlobalEventCallback<ReliableStateSyncEvent>(OnEvent);

// The following call throws a warning and does not remove the callback:
BoltNetwork.RemoveGlobalEventCallback<ReliableStateSyncEvent>(OnEvent);

Expected behavior The callback would be removed.

Actual behavior The warning is thrown, the callback is not removed.

Screenshots Not applicable.

Desktop (If applicable, please complete the following information):

Smartphone (If applicable, please complete the following information):

Additional context

ramonmelo commented 4 years ago

Hello @heilhead ,

Fixed on the next release.

Thanks for your feedback.