From 9508aaf4766dac392686301bff0d9fb4543ed75a Mon Sep 17 00:00:00 2001 From: alcomposer Date: Sat, 23 Mar 2024 17:52:01 +1030 Subject: [PATCH] fix crash on w11 opengl when resizing window from corner: https://github.com/ocornut/imgui/issues/3321 --- Source/NVGSurface.cpp | 28 ++++++++++++++++++++++++++++ Source/NVGSurface.h | 14 +++++++++++++- Source/PluginEditor.cpp | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Source/NVGSurface.cpp b/Source/NVGSurface.cpp index fc340f1ad..f9a5356b9 100644 --- a/Source/NVGSurface.cpp +++ b/Source/NVGSurface.cpp @@ -87,6 +87,8 @@ NVGSurface::NVGSurface(PluginEditor* e) : editor(e) setInterceptsMouseClicks(false, false); setWantsKeyboardFocus(false); + + setSize(1,1); // Start rendering asynchronously, so we are sure the window has been added to the desktop // kind of a hack, but works well enough @@ -103,6 +105,15 @@ NVGSurface::~NVGSurface() detachContext(); } +#ifdef LIN_OR_WIN +void NVGSurface::timerCallback() +{ + updateBounds(newBounds); + if (getBounds() == newBounds) + stopTimer(); +} +#endif + void NVGSurface::triggerRepaint() { @@ -145,6 +156,17 @@ float NVGSurface::getRenderScale() const #endif } +void NVGSurface::updateBounds(Rectangle bounds) +{ + newBounds = bounds; + if (hresize) + setBounds(bounds.withHeight(getHeight())); + else + setBounds(bounds.withWidth(getWidth())); + + resizing = true; +} + void NVGSurface::resized() { #ifdef NANOVG_METAL_IMPLEMENTATION @@ -266,6 +288,12 @@ void NVGSurface::render() #ifdef NANOVG_GL_IMPLEMENTATION glContext->swapBuffers(); + if (resizing) { + hresize = !hresize; + resizing = false; + } + if (getBounds() != newBounds) + startTimerHz(60); #endif needsBufferSwap = false; } diff --git a/Source/NVGSurface.h b/Source/NVGSurface.h index e4592c996..a25ec48b4 100644 --- a/Source/NVGSurface.h +++ b/Source/NVGSurface.h @@ -22,7 +22,8 @@ public NSViewComponent #elif NANOVG_METAL_IMPLEMENTATION && JUCE_IOS public UIViewComponent #else -public Component +#define LIN_OR_WIN +public Component, public Timer #endif { public: @@ -34,8 +35,15 @@ public Component void detachContext(); bool makeContextActive(); + +#ifdef LIN_OR_WIN + void timerCallback() override; +#endif + float getRenderScale() const; + + void updateBounds(Rectangle bounds); private: @@ -49,6 +57,10 @@ public Component NVGcontext* nvg = nullptr; bool needsBufferSwap = false; std::unique_ptr vBlankAttachment; + + bool hresize = false; + bool resizing = false; + Rectangle newBounds; #if NANOVG_GL_IMPLEMENTATION std::unique_ptr glContext; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index e51e0f88a..55b8e6bdb 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -491,7 +491,7 @@ void PluginEditor::resized() auto workArea = Rectangle(paletteWidth, toolbarHeight, (getWidth() - sidebar->getWidth() - paletteWidth), workAreaHeight); splitView.setBounds(workArea); - nvgSurface.setBounds(workArea.withTrimmedTop(31)); + nvgSurface.updateBounds(workArea.withTrimmedTop(31)); sidebar->setBounds(getWidth() - sidebar->getWidth(), toolbarHeight, sidebar->getWidth(), workAreaHeight);