Skip to content

Commit

Permalink
kinda ensure to run MessageManager on the app's main thread for Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed May 20, 2024
1 parent 07d6a30 commit 8d190da
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion aap-modules/aap_audio_processors/juceaap_AAPWrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class JuceAAPWrapper : juce::AudioPlayHead, juce::AudioProcessorListener {
#endif
plugin_unique_id = pluginUniqueId == nullptr ? nullptr : strdup(pluginUniqueId);

juce::MessageManager::getInstance(); // ensure that we have a message loop.
// Note that if we did not have invoked MessageManager::getInstance() until here, it will crash.
// It must have been done at initialiseJUCE().
juce_processor = createPluginFilter();

buildParameterList();
Expand Down
22 changes: 18 additions & 4 deletions juce-patches/7.0.6/support-plugin-ui.patch
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
diff --git a/modules/juce_core/native/juce_Threads_android.cpp b/modules/juce_core/native/juce_Threads_android.cpp
index efbf3a9f6..099e67fb5 100644
index 68967499c..e94d3e5ea 100644
--- a/modules/juce_core/native/juce_Threads_android.cpp
+++ b/modules/juce_core/native/juce_Threads_android.cpp
@@ -269,7 +269,7 @@ private:
@@ -269,7 +269,8 @@ private:

//==============================================================================
#if JUCE_MODULE_AVAILABLE_juce_events && JUCE_ANDROID
-void juce_juceEventsAndroidStartApp();
+extern "C" void juce_juceEventsAndroidStartApp();
+void juce_ensureEventsLoopStarted();
#endif

void Thread::initialiseJUCE (void* jniEnv, void* context)
@@ -303,7 +303,7 @@ void Thread::initialiseJUCE (void* jniEnv, void* context)
@@ -303,7 +304,8 @@ void Thread::initialiseJUCE (void* jniEnv, void* context)
JuceActivityWatcher::getInstance();

#if JUCE_MODULE_AVAILABLE_juce_events && JUCE_ANDROID
- juce_juceEventsAndroidStartApp();
+ //juce_juceEventsAndroidStartApp();
+ juce_ensureEventsLoopStarted();
#endif
}
}
diff --git a/modules/juce_events/native/juce_Messaging_android.cpp b/modules/juce_events/native/juce_Messaging_android.cpp
index 8062840f2..84f1c7679 100644
index 7cf749f95..86fe6816a 100644
--- a/modules/juce_events/native/juce_Messaging_android.cpp
+++ b/modules/juce_events/native/juce_Messaging_android.cpp
@@ -288,8 +288,8 @@ private:
Expand All @@ -35,3 +37,15 @@ index 8062840f2..84f1c7679 100644
{
auto dllPath = juce_getExecutableFile().getFullPathName();
auto addr = reinterpret_cast<juce::JUCEApplicationBase*(*)()> (DynamicLibrary (dllPath)
@@ -299,4 +299,11 @@ void juce_juceEventsAndroidStartApp()
JuceAppLifecycle::getInstance (addr);
}

+void juce_ensureEventsLoopStarted()
+{
+ // This ensures that event loop exists and it's on Android's main thread.
+ // Note that to ensure that it is the main thread, it must be indeed invoked as such e.g. at androidx.startup.
+ MessageManager::getInstance();
+}
+
} // namespace juce

0 comments on commit 8d190da

Please sign in to comment.