From 87d3acf19f3aead5fe0cd27e5b83c776da4b4f94 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 30 Mar 2012 09:31:35 +0100 Subject: [PATCH] Message leak fix. Android repaint fix. Minor clean-ups. --- .../format_types/juce_VSTMidiEventList.h | 6 +-- modules/juce_core/memory/juce_HeapBlock.h | 24 +++++------ .../native/juce_android_JNIHelpers.h | 5 +-- .../native/juce_win32_SystemStats.cpp | 4 +- .../juce_core/system/juce_StandardHeader.h | 1 - .../messages/juce_MessageManager.cpp | 1 + .../image_formats/juce_PNGLoader.cpp | 12 ++---- .../native/juce_android_Fonts.cpp | 34 ++++++++------- .../native/juce_android_Windowing.cpp | 42 ++++--------------- 9 files changed, 51 insertions(+), 78 deletions(-) diff --git a/modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h b/modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h index 68c0794065..89a6c395a3 100644 --- a/modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h +++ b/modules/juce_audio_processors/format_types/juce_VSTMidiEventList.h @@ -169,8 +169,8 @@ private: static VstEvent* allocateVSTEvent() { - VstEvent* const e = (VstEvent*) ::calloc (1, sizeof (VstMidiEvent) > sizeof (VstMidiSysexEvent) ? sizeof (VstMidiEvent) - : sizeof (VstMidiSysexEvent)); + VstEvent* const e = (VstEvent*) std::calloc (1, sizeof (VstMidiEvent) > sizeof (VstMidiSysexEvent) ? sizeof (VstMidiEvent) + : sizeof (VstMidiSysexEvent)); e->type = kVstMidiType; e->byteSize = sizeof (VstMidiEvent); return e; @@ -181,7 +181,7 @@ private: if (e->type == kVstSysExType) delete[] (((VstMidiSysexEvent*) e)->sysexDump); - ::free (e); + std::free (e); } }; diff --git a/modules/juce_core/memory/juce_HeapBlock.h b/modules/juce_core/memory/juce_HeapBlock.h index 324b9ef2e6..4f6a66eaaa 100644 --- a/modules/juce_core/memory/juce_HeapBlock.h +++ b/modules/juce_core/memory/juce_HeapBlock.h @@ -105,7 +105,7 @@ public: If you want an array of zero values, you can use the calloc() method instead. */ explicit HeapBlock (const size_t numElements) - : data (static_cast (::malloc (numElements * sizeof (ElementType)))) + : data (static_cast (std::malloc (numElements * sizeof (ElementType)))) { throwOnAllocationFailure(); } @@ -116,7 +116,7 @@ public: */ ~HeapBlock() { - ::free (data); + std::free (data); } #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS @@ -203,8 +203,8 @@ public: */ void malloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { - ::free (data); - data = static_cast (::malloc (newNumElements * elementSize)); + std::free (data); + data = static_cast (std::malloc (newNumElements * elementSize)); throwOnAllocationFailure(); } @@ -213,8 +213,8 @@ public: */ void calloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { - ::free (data); - data = static_cast (::calloc (newNumElements, elementSize)); + std::free (data); + data = static_cast (std::calloc (newNumElements, elementSize)); throwOnAllocationFailure(); } @@ -224,12 +224,12 @@ public: */ void allocate (const size_t newNumElements, const bool initialiseToZero) { - ::free (data); + std::free (data); if (initialiseToZero) - data = static_cast (::calloc (newNumElements, sizeof (ElementType))); + data = static_cast (std::calloc (newNumElements, sizeof (ElementType))); else - data = static_cast (::malloc (newNumElements * sizeof (ElementType))); + data = static_cast (std::malloc (newNumElements * sizeof (ElementType))); throwOnAllocationFailure(); } @@ -242,9 +242,9 @@ public: void realloc (const size_t newNumElements, const size_t elementSize = sizeof (ElementType)) { if (data == nullptr) - data = static_cast (::malloc (newNumElements * elementSize)); + data = static_cast (std::malloc (newNumElements * elementSize)); else - data = static_cast (::realloc (data, newNumElements * elementSize)); + data = static_cast (std::realloc (data, newNumElements * elementSize)); throwOnAllocationFailure(); } @@ -254,7 +254,7 @@ public: */ void free() { - ::free (data); + std::free (data); data = nullptr; } diff --git a/modules/juce_core/native/juce_android_JNIHelpers.h b/modules/juce_core/native/juce_android_JNIHelpers.h index 0831534749..4f9bd7b7f6 100644 --- a/modules/juce_core/native/juce_android_JNIHelpers.h +++ b/modules/juce_core/native/juce_android_JNIHelpers.h @@ -108,7 +108,7 @@ template class LocalRef { public: - explicit inline LocalRef (JavaType obj_) noexcept : obj (obj_){} + explicit inline LocalRef (JavaType obj_) noexcept : obj (obj_) {} inline LocalRef (const LocalRef& other) noexcept : obj (retain (other.obj)) {} ~LocalRef() { clear(); } @@ -143,8 +143,7 @@ namespace { String juceString (JNIEnv* env, jstring s) { - jboolean isCopy; - const char* const utf8 = env->GetStringUTFChars (s, &isCopy); + const char* const utf8 = env->GetStringUTFChars (s, nullptr); CharPointer_UTF8 utf8CP (utf8); const String result (utf8CP); env->ReleaseStringUTFChars (s, utf8); diff --git a/modules/juce_core/native/juce_win32_SystemStats.cpp b/modules/juce_core/native/juce_win32_SystemStats.cpp index 9e47416838..5b21f63f33 100644 --- a/modules/juce_core/native/juce_win32_SystemStats.cpp +++ b/modules/juce_core/native/juce_win32_SystemStats.cpp @@ -30,8 +30,8 @@ void Logger::outputDebugString (const String& text) //============================================================================== #ifdef JUCE_DLL - JUCE_API void* juceDLL_malloc (size_t sz) { return ::malloc (sz); } - JUCE_API void juceDLL_free (void* block) { ::free (block); } + JUCE_API void* juceDLL_malloc (size_t sz) { return std::malloc (sz); } + JUCE_API void juceDLL_free (void* block) { std::free (block); } #endif //============================================================================== diff --git a/modules/juce_core/system/juce_StandardHeader.h b/modules/juce_core/system/juce_StandardHeader.h index ff82c89483..e4dbf8547a 100644 --- a/modules/juce_core/system/juce_StandardHeader.h +++ b/modules/juce_core/system/juce_StandardHeader.h @@ -104,7 +104,6 @@ #endif #if JUCE_MSVC - #include #pragma warning (pop) #endif diff --git a/modules/juce_events/messages/juce_MessageManager.cpp b/modules/juce_events/messages/juce_MessageManager.cpp index 2e94a20682..a345314833 100644 --- a/modules/juce_events/messages/juce_MessageManager.cpp +++ b/modules/juce_events/messages/juce_MessageManager.cpp @@ -103,6 +103,7 @@ void MessageManager::runDispatchLoop() void MessageManager::stopDispatchLoop() { (new QuitMessage())->post(); + quitMessagePosted = true; } bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor) diff --git a/modules/juce_graphics/image_formats/juce_PNGLoader.cpp b/modules/juce_graphics/image_formats/juce_PNGLoader.cpp index faa0ded8db..dc3ca38d07 100644 --- a/modules/juce_graphics/image_formats/juce_PNGLoader.cpp +++ b/modules/juce_graphics/image_formats/juce_PNGLoader.cpp @@ -50,12 +50,12 @@ namespace pnglibNamespace #if JUCE_INCLUDE_PNGLIB_CODE || ! defined (JUCE_INCLUDE_PNGLIB_CODE) #if _MSC_VER != 1310 - using ::calloc; // (causes conflict in VS.NET 2003) - using ::malloc; - using ::free; + using std::calloc; // (causes conflict in VS.NET 2003) + using std::malloc; + using std::free; #endif - using ::abs; + using std::abs; #define PNG_INTERNAL #define NO_DUMMY_DECL #define PNG_SETJMP_NOT_SUPPORTED @@ -95,10 +95,6 @@ namespace pnglibNamespace #pragma warning (pop) #endif -using ::calloc; -using ::malloc; -using ::free; - //============================================================================== namespace PNGHelpers { diff --git a/modules/juce_graphics/native/juce_android_Fonts.cpp b/modules/juce_graphics/native/juce_android_Fonts.cpp index a0fb42d8eb..a04c522363 100644 --- a/modules/juce_graphics/native/juce_android_Fonts.cpp +++ b/modules/juce_graphics/native/juce_android_Fonts.cpp @@ -180,28 +180,30 @@ public: const Rectangle bounds (left, top, right - left, bottom - top); - if (bounds.isEmpty()) - return nullptr; + EdgeTable* et = nullptr; - jint* const maskDataElements = env->GetIntArrayElements (maskData, 0); + if (! bounds.isEmpty()) + { + et = new EdgeTable (bounds); - EdgeTable* et = new EdgeTable (bounds); + jint* const maskDataElements = env->GetIntArrayElements (maskData, 0); + const jint* mask = maskDataElements; - const jint* mask = maskDataElements; + for (int y = top; y < bottom; ++y) + { + #if JUCE_LITTLE_ENDIAN + const uint8* const lineBytes = ((const uint8*) mask) + 3; + #else + const uint8* const lineBytes = (const uint8*) mask; + #endif - for (int y = top; y < bottom; ++y) - { - #if JUCE_LITTLE_ENDIAN - const uint8* const lineBytes = ((const uint8*) mask) + 3; - #else - const uint8* const lineBytes = (const uint8*) mask; - #endif - - et->clipLineToMask (left, y, lineBytes, 4, bounds.getWidth()); - mask += bounds.getWidth(); + et->clipLineToMask (left, y, lineBytes, 4, bounds.getWidth()); + mask += bounds.getWidth(); + } + + env->ReleaseIntArrayElements (maskData, maskDataElements, 0); } - env->ReleaseIntArrayElements (maskData, maskDataElements, 0); env->DeleteLocalRef (maskData); return et; } diff --git a/modules/juce_gui_basics/native/juce_android_Windowing.cpp b/modules/juce_gui_basics/native/juce_android_Windowing.cpp index 3902c72799..5f119536cf 100644 --- a/modules/juce_gui_basics/native/juce_android_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_android_Windowing.cpp @@ -45,6 +45,8 @@ JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, launchApp, void, (JNIEnv* en JUCEApplication* app = dynamic_cast (JUCEApplicationBase::createInstance()); if (! app->initialiseApp (String::empty)) exit (0); + + jassert (MessageManager::getInstance()->isThisTheMessageThread()); } JUCE_JNI_CALLBACK (JUCE_ANDROID_ACTIVITY_CLASSNAME, quitApp, void, (JNIEnv* env, jobject activity)) @@ -386,7 +388,7 @@ public: jint* dest = env->GetIntArrayElements ((jintArray) buffer.get(), 0); - if (dest != 0) + if (dest != nullptr) { { Image temp (new PreallocatedImage (clip.getWidth(), clip.getHeight(), @@ -415,26 +417,23 @@ public: } else { - class ViewRepainter : public CallbackMessage + struct ViewRepainter : public CallbackMessage { - public: ViewRepainter (const GlobalRef& view_, const Rectangle& area_) - : view (view_), area (area_) - { - post(); - } + : view (view_), area (area_) {} void messageCallback() { - view.callVoidMethod (ComponentPeerView.invalidate, area.getX(), area.getY(), area.getRight(), area.getBottom()); + view.callVoidMethod (ComponentPeerView.invalidate, area.getX(), area.getY(), + area.getRight(), area.getBottom()); } private: GlobalRef view; - const Rectangle& area; + const Rectangle area; }; - new ViewRepainter (view, area); + (new ViewRepainter (view, area))->post(); } } @@ -448,29 +447,6 @@ public: // TODO } - #if USE_ANDROID_CANVAS - StringArray getAvailableRenderingEngines() - { - StringArray s (ComponentPeer::getAvailableRenderingEngines()); - s.add ("Android Canvas Renderer"); - return s; - } - - int getCurrentRenderingEngine() const - { - return usingAndroidGraphics ? 1 : 0; - } - - void setCurrentRenderingEngine (int index) - { - if (usingAndroidGraphics != (index > 0)) - { - usingAndroidGraphics = index > 0; - component->repaint(); - } - } - #endif - //============================================================================== static AndroidComponentPeer* findPeerForJavaView (JNIEnv* env, jobject viewToFind) {