Skip to content

Commit

Permalink
fix crash on w11 opengl when resizing window from corner: ocornut/img…
Browse files Browse the repository at this point in the history
  • Loading branch information
alcomposer committed Mar 23, 2024
1 parent 8ad7fad commit 9508aaf
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
28 changes: 28 additions & 0 deletions Source/NVGSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -103,6 +105,15 @@ NVGSurface::~NVGSurface()
detachContext();
}

#ifdef LIN_OR_WIN
void NVGSurface::timerCallback()
{
updateBounds(newBounds);
if (getBounds() == newBounds)
stopTimer();
}
#endif


void NVGSurface::triggerRepaint()
{
Expand Down Expand Up @@ -145,6 +156,17 @@ float NVGSurface::getRenderScale() const
#endif
}

void NVGSurface::updateBounds(Rectangle<int> bounds)
{
newBounds = bounds;
if (hresize)
setBounds(bounds.withHeight(getHeight()));
else
setBounds(bounds.withWidth(getWidth()));

resizing = true;
}

void NVGSurface::resized()
{
#ifdef NANOVG_METAL_IMPLEMENTATION
Expand Down Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion Source/NVGSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -34,8 +35,15 @@ public Component

void detachContext();
bool makeContextActive();

#ifdef LIN_OR_WIN
void timerCallback() override;
#endif


float getRenderScale() const;

void updateBounds(Rectangle<int> bounds);

private:

Expand All @@ -49,6 +57,10 @@ public Component
NVGcontext* nvg = nullptr;
bool needsBufferSwap = false;
std::unique_ptr<VBlankAttachment> vBlankAttachment;

bool hresize = false;
bool resizing = false;
Rectangle<int> newBounds;

#if NANOVG_GL_IMPLEMENTATION
std::unique_ptr<OpenGLContext> glContext;
Expand Down
2 changes: 1 addition & 1 deletion Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ void PluginEditor::resized()

auto workArea = Rectangle<int>(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);

Expand Down

0 comments on commit 9508aaf

Please sign in to comment.