Read access violation on (MouseListener& l) in callChecked

Stress testing my plugins shows crashes in ableton and throws a read access violation exception. Any help will be appreciated!

The code stops at:
Desktop::getInstance().getMouseListeners().callChecked (checker, [&] (MouseListener& l) { l.mouseEnter (me); }); or
mouseListeners.callChecked (checker, [&] (MouseListener& l) { l.mouseMove (me); });

in for example:

  • from mouseEnter into the UI? with Component::internalMouseEnter (is this called for juce or for mouseEnter on my components?)
  • from a timer callback with Desktop::sendMouseMove()

I don’t know where this is comming from exactly and which of my code is associated, but it seems to happen when the editor window is closed or opened, does anyone know how to debug this propperly and possibly give a direction to where the error might come from?

This means that one of your mouse listeners is being called, although it no longer exists.

When adding a mouse listener, make sure to remove this listener when the listener is being destroyed :slight_smile:

This is something I have not done for all cases with the following as reference:
Do I have to removeMouseListener before I delete component? - #2 by loopfine.

I thought that this should not be needed, all mouse listeners that I use are implemented as interface on UI components, should I still remove it in the deconstructor? Then again there is also the issue on the timer callback, which is basically the same thing, it only exists on the message thread, and is used as interface on some UI components. I also don’t know why the timercallback should trigger a mousemove action

Generally, always remove any mouse listener before destroying it.

The post you mentioned is something fundamentally different: The object that sends the message (eg. mouseMove) is being destroyed.
When the object you are listening to is being destroyed, you just wont get any mouse callbacks from it.

You destroy the object that listens to another object. The other object cant know that a listener has been destroyed.

Remove the listeners before destroying them.

Thanks @moritzsur ! I have added the removemouselistener functions in the deconstructor and as of now the issue is not reproducable. it is difficult to say that is really gone now, but for now it looks like this is resolved, thanks!

I shouted too soon, even with removing the listeners this exception is still thrown… I have to do some more debugging…

I don’t know your use case. I wonder why you use Desktop::getInstance()? I think you should avoid that at all in a plugin. Why not use mouseEnter on your editor Component? Every Component already listens to mouse events.

This is what use actually, the code shown is from Juce getting from a mouse event to the component callback I guess. I have had a little bit more time to get into the issue, it looks like I missed a removing listener function (:zipper_mouth_face:). And I have one special case with using a global mouse listener which is updated with parentHierarchyChanged(), for this I had to duplicate the functions from parentHierarchyChanged() to also add and remove listeners in the constructor and deconstructor of that component. I keep debugging, but this might be it!