I finally got the approval of my client to look into this issue further. The following is the case:
If I leave the resized() function of my main DocumentWindow empty and set a breakpoint there (after my app is loaded, as it calls resized() many times during startup), everything works as expected - every time I rotate my device, the breakpoint suspends the application.
If I now add normal stuff to the resized() body, like for example
int i = 5;
int j = 7;
int minInt = std::min(5, 7);
int maxInt = std::max(5, 7);
same thing happens. But of course it is not my intention to calculate useless numbers.
Some background information. I have a Viewport named viewport as the main component of the DocumentWindow, which itself holds a standard Component named windowManager that manages the content of my app. When rotating the device, I need to resize viewport (swap width and height, so newWidth = oldHeight and newHeight = oldWidth) as well as windowManager.
I tried that and everything worked perfectly when going from portrait to landscape. But when I tried turning it back to landscape, resized() of my main window is never called again as are the resized() methods of the child components.
void resized()
{
if (viewport != nullptr && windowManager != nullptr)
{
int minDim = min(displayArea.getWidth(), displayArea.getHeight());
int maxDim = max(displayArea.getWidth(), displayArea.getHeight());
if (AdditionalFuncs::isUpright())
{
viewport->setSize(minDim, maxDim);
}
else
{
viewport->setSize(maxDim, minDim);
}
windowManager->setSize(viewport->getWidth() - (viewport->isVerticalScrollBarShown() ? viewport->getScrollBarThickness() : 0),
viewport->getHeight() - (viewport->isHorizontalScrollBarShown() ? viewport->getScrollBarThickness() : 0) + 200);
}
}
First I thought it had something to do with kind of a feedback loop, because only when I introduced the setSize calls, the resized() method of the main window gets called multiple times, instead of one time, per rotation. Still after trying to “rotate back”, resized() gets never called again.
Because I assumed that it had something to do with the multiple calls to the main window resized() method, I changed all of this to
void resized()
{
if (viewport != nullptr && windowManager != nullptr && !lockResize)
{
lockResize = true;
int minDim = min(displayArea.getWidth(), displayArea.getHeight());
int maxDim = max(displayArea.getWidth(), displayArea.getHeight());
if (AdditionalFuncs::isUpright())
{
viewport->setSize(minDim, maxDim);
}
else
{
viewport->setSize(maxDim, minDim);
}
windowManager->setSize(viewport->getWidth() - (viewport->isVerticalScrollBarShown() ? viewport->getScrollBarThickness() : 0), viewport->getHeight() - (viewport->isHorizontalScrollBarShown() ? viewport->getScrollBarThickness() : 0) + 200);
Timer::callAfterDelay(500, [this] () { this->lockResize = false; });
}
}
I have a member variable bool lockResize which defaults to false, so it only calls my specific stuff once per rotation, but doesn’t block any other needed operation. And voila my stuff is only called once… But… rotating back still messes things up, so resized() is never called again.
I have no idea where to look or what to do as it seems to be very specific. But I don’t see why it shouldn’t work…
To ensure that my code is not the problem, I have stripped it down as far as possible. As I said, if I remove everything inside resized(), said method gets called like one would expect…
You can find the stripped down version under https://gist.github.com/DustVoice/44fbc972f6d0a67717fb057ae9ee82ec. I would love some assistance on this matter.