DocumentWindow stops capturing mouse clicks after being resized when it is in a PluginEditor on Windows. The problem is not present when compiling as a Standalone but is when in a VST3. Everything works fine in JUCE 7.
Steps to reproduce:
Start a new plugin project.
Add a juce::DocumentWindow to the Editor.
Use the constructor below.
Compile and open the VST3.
Resize the window by dragging on the bottom right corner.
The DocumentWindow no longer responds to clicks. Impossible to move or resize it.
Setting the background alpha to 1.f solves the problem and the window reacts as expected after being resized.
Any ideas why this might be happening and if there is a work around I could in the meantime? It’s odd that Standalone isn’t impacted but VST3 is.
It looks like the problem was introduced when Direct2D was implemented. It works fine on the commit just before this:
I’ve had a go at trying to track down why it acts differently between the Standalone and VST3 builds but I don’t have enough of an understanding of Direct2D.
Using the following code in the constructor means that the DocumentWindow passes the clicks through as soon as it becomes visible, rather than having to manually resize:
docWin.setSize(300, 300);
docWin.setTopLeftPosition(400, 400);
docWin.setAlwaysOnTop(true);
docWin.setVisible(true);
docWin.setResizable(true, true);
docWin.setInterceptsMouseClicks(true, true);
docWin.addToDesktop();
docWin.setSize(301, 300); // <- Resize the window here. If this line is included then window doesn't respond to clicks
Something that is happening in setSize() is breaking transparent DocumentWindows but I don’t see what it could be, not why it is different for Standalone.
I’ll keep looking but if anyone with more D2D knowledge than me can help that would be great
This is a bit weird. I’ve started investigating, but haven’t made much progress yet. Interestingly, the issue doesn’t seem to affect all VST3 hosts. REAPER is affected, but the JUCE AudioPluginHost isn’t. So far I’m not sure what causes the difference in behaviour.
I did all my testing in Reaper, so that explains the difference with Standalone. I spent all day yesterday digging through the code but didn’t find much.
All I found was that overriding DocumentWindow::resized and adding the mouse listener back again allows the window to respond to clicks again but not for the whole bounds (it also causes massive glitches while resizing). Not sure if that is in any way helpful.
I’ve been doing a bit of debugging for this issue this morning. No real luck. I thought that it was because in Reaper the VST3 createView() function is not getting called after the second setSize() in the snippet above. In AudioPluginHost this is called after setSize(). But it’s actually the same with a non-transparent window, which works as expected, so it probably isn’t that…
The only other thing I have seen so far is the comments in the constructor of D2DContext, but I still don’t see what is happening differently between hosts that could make it relevant:
Hi @reuk, sorry to keep spamming this post. I have been looking into this again. To try to work around this issue I thought I’d try the software renderer and I’m encountering a different problem.
If I set the DocumentWindow to render using the software renderer (docWin.getPeer()->setCurrentRenderingEngine(0)) then I start hitting this assert:
I hit the assert even when building as a standalone, so I don’t know if this is in any way related to the original error other than it also only happens for transparent DocumentWindows.
I tested in JUCE 7 and added the same assert but things seem to be working fine.
@reuk Any timeline for this issue or is the best solution to roll back to the unbroken JUCE 7 for the time being? I have a release planned that relies on this and it would have been better to use JUCE 8 for some other features but this is a roadblock. Thanks!
I’m not able to guess when we’ll have a fix ready, unfortunately. This is still on my backlog, but my backlog is very full at the moment!
While I am planning to look at this, I’d like to mention that additional windows are very problematic in AUv3 (and to a lesser extent, AU), so if you’re planning on supporting macOS/iOS then you may need to consider an approach that avoids additional windows. In general I’d recommend to restrict all controls to the main editor window as much as possible.
Thanks for the update. Just wanted to check if I should wait a few weeks for a fix or if it’s better to move ahead with JUCE 7. I’ll roll back to the working version for now.
I’m targeting AU/AUv3 so that shouldn’t be a problem but thanks for the warning.
Thanks for your patience. I ended up having to make several different attempts at resolving this issue, which is why it took so long. Please let us know if you find any issues in the new implementation:
I’ve just tested and it all seems to be working fine but I keep hitting this jassert:
This happens for both DocumentWindows added to both Standalone and VST3 plugins when clicking the maximise button. It only happens for transparent windows.
I also hit the jassert when I drag the DocumentWindow from one screen to another.
Testing in Release mode everything seems to be working as expected.
Thanks for letting me know. An error returned by EndFrame just indicates that something went wrong while drawing the frame. Please could you try changing the constant on this line to D2D1_DEBUG_LEVEL_INFORMATION and checking the console/debugger output to see whether any additional information gets printed?
D2D DEBUG ERROR - An operation failed because a device-dependent resource is associated with the wrong ID2D1Device (resource domain).
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in reaper.exe.
D2D DEBUG ERROR - BeginDraw was called but will be ignored because the device context is in an invalid state.
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in reaper.exe.
D2D DEBUG WARNING - EndDraw was called, but the rendertarget was not in a valid state. This may result from calling EndDraw without a matching BeginDraw.
D2D DEBUG WARNING - A Draw call by a render target failed [88990015]. Tags [0x0, 0x0].
JUCE Assertion failure in juce_Direct2DGraphicsContext_windows.cpp:640
With the debugging set Visual Studio also pauses on lines 616 and 617 of juce_Direct2DGraphicsContext_windows.cpp:
Do you have multiple displays or graphics cards connected? I’m currently unsure how to reproduce the issue. The error text is fairly clear about what’s going wrong, but without being able to reproduce the problem it’s difficult to know why images are being incorrectly shared across devices.
Yes, I was using both screens when I hit the asserts.
When I close the lid on my laptop and just use the external screen I don’t hit the assert.
There are two GPUs built in to the laptop: Intel Iris Xe Graphics and NVIDIA GeForce RTX 3060 Laptop GPU
While interacting with the window it looks like it is mostly the Intel card that is bring used but there is perhaps some small (2-3%) use of the NVDIA.
Thanks for the extra details, I’ve managed to find a computer setup that reproduces the issue. I’ll investigate and update this thread once there’s a fix available.