Windows sometimes incorrectly resized


#1

Hi Jules,

Sometimes on startup, my app ends with a 1x1 window instead of its correct dimension (500x500). This happens with native border, or without it. The occurence of the bug is highly dependent on the timing of X11 events and the interaction with the WManager so I have had a hard time catching it in a debugger. Here is what happens:

  • The top-level window component is created, its addToDesktop param is true so it gets added to the desktop, with its default size that is 1x1
  • LinuxComponentPeer::setBounds(1,1) is called by addToDesktop
  • later in the code, its real size is set, and LinuxComponentPeer::setBounds(500,500) gets called

both calls to setBounds will resize the window. The windowmanager will be notified, will perform the resize, and will send a ConfigureNotify event back to us. In general , juce only receives the ConfigureNotify for the the 500x500 resize, and none for the first resize. But sometimes, it first receives ConfigureNotify for the 1x1 resize, and then you have a sequence of calls inside the handler for ConfigureNotify that leads to a new call to setBounds(1,1) , with the following stack trace:

#3 0x082e9009 in juce::LinuxComponentPeer::setBounds (this=0x1352c5e0, x=26, y=0, w=2, h=22, isNowFullScreen=false) at juce/juce_amalgamated.cpp:249404
#4 0x08283219 in juce::LinuxComponentPeer::setSize (this=0x1352c5e0, w=2, h=22) at juce/juce_amalgamated.cpp:249397
#5 0x082e94c2 in juce::Component::setBounds (this=0x1352c4d8, x=26, y=0, w=2, h=22) at juce/juce_amalgamated.cpp:36161
#6 0x082eb534 in juce::Component::setSize (this=0x1352c4d8, w=2, h=22) at juce/juce_amalgamated.cpp:36212
#7 0x082eb5c9 in juce::ResizableWindow::childBoundsChanged (this=0x1352c4d8, child=0x1355e9c8) at juce/juce_amalgamated.cpp:71830
#8 0x082e8b39 in juce::Component::sendMovedResizedMessages (this=0x1355e9c8, wasMoved=false, wasResized=true) at juce/juce_amalgamated.cpp:36189
#9 0x082e94dd in juce::Component::setBounds (this=0x1355e9c8, x=1, y=21, w=0, h=0) at juce/juce_amalgamated.cpp:36165
#10 0x08340997 in juce::Component::setBoundsInset (this=0x1355e9c8, borders=@0xbf847300) at juce/juce_amalgamated.cpp:36270
#11 0x08340b67 in juce::ResizableWindow::resized (this=0x1352c4d8) at juce/juce_amalgamated.cpp:71810
#12 0x08340b95 in juce::DocumentWindow::resized (this=0x1352c4d8) at juce/juce_amalgamated.cpp:71503
#13 0x08340d13 in juce::DialogWindow::resized (this=0x1352c4d8) at juce/juce_amalgamated.cpp:71272
#14 0x082e8aa7 in juce::Component::sendMovedResizedMessages (this=0x1352c4d8, wasMoved=true, wasResized=true) at juce/juce_amalgamated.cpp:36178
#15 0x082e8d80 in juce::ComponentPeer::handleMovedOrResized (this=0x1352c5e0) at juce/juce_amalgamated.cpp:71043
#16 0x08345deb in juce::LinuxComponentPeer::handleWindowMessage (this=0x1352c5e0, event=0xbf8476e0) at juce/juce_amalgamated.cpp:250198
#17 0x08346344 in juce::juce_windowMessageReceive (event=0xbf8476e0) at juce/juce_amalgamated.cpp:251218
#18 0x0834657d in juce::juce_dispatchNextMessageOnSystemQueue (returnIfNoPendingMessages=false) at juce/juce_amalgamated.cpp:248091

(ok here it is setBounds(2,22) instead of (1,1) because of its non-native border)

So it that case, the window is finally resized to 2x22 instead of 500x500

An ugly workaround is to increment a flag “inConfigureNotify” at the begin of the handler of ConfigureNotify, decrement it at the end , and do the following test at the beginning of LinuxComponentPeer::setBounds:

if (inConfigureNotify) { wx = x; wy = y; ww = jmax(1,w); wh = jmax(1,h); return; }


#2

Hmm. Would it be better to stop ConfigureNotify making the call to handleMovedOrResized()? Perhaps it could check whether the size is (1, 1) or something…


#3

Yes testing on the 1x1 size before calling handleMovedOrResized also works on my particular case


#4

Not so good if you actually want to resize a window to 1x1 though… Hmm. Not sure what’s best here.


#5

Yes I think my initial solution, while not elegant at all, is better, except if the user wants to do some tricky stuff such as resizing his window in the MovedOrResized handler

Or you may want to wait and not apply any fix – so far I could not reproduce the bug with the juce demo.