aleclarson / emitter-kit

Type-safe event handling for Swift
MIT License
567 stars 71 forks source link

Force unwrapping cause crashes #58

Closed wqz-leo closed 5 years ago

wqz-leo commented 5 years ago

Screen Shot 2019-03-29 at 11 35 29 am

Please find the crash in the screenshot above. As mentioned in #57, force unwrapping _listeners[_targetID] is causing the crash because there's no value in _listeners.

aleclarson commented 5 years ago

Okay, setup a git repo and I'll take a look.

https://stackoverflow.com/help/mcve

wqz-leo commented 5 years ago

Unfortunately, it's not easy to replicate the same situation, and I'm not able to share my source code. Here's what happened in theory: I'm downloading some videos in my app, download progress is received from URLSession and pass value to Event, then the event emits progress on main thread by wrapping into DispatchQueue.main.async. On navigating back, I call listener.isListening = false in deinit and that's the place where crash happens.

aleclarson commented 5 years ago

The _stopListening method of EventListener should never crash. Your downloadStateListener is being removed from its event while its isListening property is still true. If you can find where that's happening, we can track down the real bug.

Side note: You don't need to set downloadStateListener.isListening = false manually. When your DownloadButton instance is released, the listener is removed from its event automatically.