# MessageQueue recursive callback

**URL:** <https://forum.juce.com/t/messagequeue-recursive-callback/12961>\
**Category:** MacOSX and iOS\
**Created:** [June 7, 2014, 8:22pm UTC](https://forum.juce.com/t/messagequeue-recursive-callback/12961 "2014-06-07T20:22:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![graeme-2](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@graeme-2](https://forum.juce.com/u/graeme-2)\
**Post date:** [June 7, 2014, 8:22pm UTC](https://forum.juce.com/t/messagequeue-recursive-callback/12961/1 "2014-06-07T20:22:09Z")

</div>

Hi Jules, I've found a situation where the message queue's runLoopSource gets called back recursively. &nbsp;It occurs due to a plugin invoking the runloop&nbsp;when it's state information is loaded (the plugin is the NI Kontakt player). &nbsp;I've attached an image of the stack trace.

Due to this I have a&nbsp;handleAsyncUpdate that appears to get invoked twice in the same effective pass of the run loop, which I don't think should be expected? &nbsp;I dug through apple's&nbsp;run loop docs looking for&nbsp;a way to deal with it but wasn't able to sort anything much out of it.&nbsp;&nbsp;I tested out just using an "in progress" flag in&nbsp;runLoopCallback&nbsp;to stop the recursion which appears to work ok.&nbsp; I can also do this directly in my handleAsyncUpdate easily enough but it's kinda hacky I think.

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 8, 2014, 8:39am UTC](https://forum.juce.com/t/messagequeue-recursive-callback/12961/2 "2014-06-08T08:39:22Z")

</div>

Jeez... This is why plugins should NEVER RUN MODAL LOOPS!!

Unfortunately, if the stupid thing decides to run a loop in the middle of a call to&nbsp;setStateInformation() then there's nothing you can really do about that other than hacks to avoid problems when it happens.

Trying to stop runLoopCallback() being called recursively isn't a good plan though, since there are times when you actually do want that to happen. It'd be better to stop the async event getting re-triggered, so maybe find out when triggerAsyncCallback gets called, and stop that somehow.

A trick I find useful for this sort of thing is to create a stack-local dummy&nbsp;Component and put it into a modal state&nbsp;before calling setStateInformation, so that will at least block any input&nbsp;events from reaching your GUI while the plugin is busy. It won't stop your timers or other events from getting called though.

---

<div class="post-metadata">

**Author:** ![graeme-2](https://avatars.discourse-cdn.com/v4/letter/g/8baadc/32.png) [@graeme-2](https://forum.juce.com/u/graeme-2)\
**Post date:** [June 9, 2014, 1:03am UTC](https://forum.juce.com/t/messagequeue-recursive-callback/12961/3 "2014-06-09T01:03:13Z")

</div>

Yeah it looks like it's due to a "loading" popup that it likes&nbsp;to popup repeatedly and&nbsp;quite pointlessly a few microseconds at a time.&nbsp; Perhaps if someday you decide to put together that&nbsp;juce plugin format you could then enforce no modal loops, and&nbsp;there could be an api to allow the host to monitor a plugin's loading progress&nbsp;so the host could manage the displaying of that sort of thing itself. &nbsp;That would be nice. &nbsp;

I'll leave the queue alone and go with my local hack.&nbsp; Thanks for the tips!

---

<div class="post-metadata">

**Author:** ![fireplayer](https://avatars.discourse-cdn.com/v4/letter/f/48db29/32.png) [@fireplayer](https://forum.juce.com/u/fireplayer)\
**Post date:** [January 20, 2015, 4:39pm UTC](https://forum.juce.com/t/messagequeue-recursive-callback/12961/4 "2015-01-20T16:39:00Z")

</div>

I have another problem with Kontakt 5 player.

When you try to close it's window, it hangs in the following code:

```
bool WaitableEvent::wait (const int timeOutMs) const noexcept
{
    return WaitForSingleObject (handle, (DWORD) timeOutMs) == WAIT_OBJECT_0;
}
```

This also occurs in the demo host and&nbsp;Tracktion 5.

I believe it is a Kontakt 5 problem, but&nbsp;does anyone have a fix.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 20, 2015, 6:01pm UTC](https://forum.juce.com/t/messagequeue-recursive-callback/12961/5 "2015-01-20T18:01:16Z")

</div>

Can't you share a more useful stack-trace? That method is obviously called from thousands of places, it tells us nothing without some context..
