Multiple paints


#1

The paint routine is always getting called twice on Linux (but not on OS X, using identical code).  This is simply a derivative of Component.

The double paint happens when the component is first drawn as well as when I resize it.  This is on 64 bit Linux (Mint 17.1). Again, OS X does not exhibit this.

I noticed because the initial display is also very slow, and I wondered what's going on.  But the total time in my paint handler is only about 10-15 msec, which would not be enough to notice...


#2

Ok, but what's the sequence of calls that makes this happen? Is it a mistake, or perhaps it's actually because the X server is sending multiple repaint messages?


#3

I get the same thing when I remove all of my painting code, and just printf that a paint call happened.  The scenario is a simple window with three components, with bounds so they keep their places:

loc: "0,0,parent.width,parent.height/10"

date: "0,loc.bottom,parent.width,top+loc.height"

clock: "0,date.bottom,parent.width,parent.height"

 

Could it be that because the top of one is the bottom of the previous that could cause an issue?  It *looks* ok...


#4

No,  that's not the problem...


#5

I'd need more detail of exactly which bit of code is doing its job incorrectly to convince me that this is a real issue. Repaints happen all the time, and maybe X really is just sending two repaints..


#6

OK, disentangling my stuff from the JUCE code is not a trivial issue.  I'll try to make a test sample


#7

Attached is a test case.  When I start it I see "paint!" twice, even though absolutely nothing is going on inside the code.

Damn.  I was going to upload it, but your forum doesn't allow zips.  So I've uploaded it onto Box:

 

https://app.box.com/s/idgafy1bsehw09zdro5fi6r25ij8khkx


#8

But any running app will involve millions of repaints... Just getting the window on screen will obviously involve painting. I don't understand exactly what it is that you think is wrong?


#9

I think it is wrong that the window gets two repaints, when one should suffice.  You think it's ok for the paint to repaint after it just painted?


#10

I'd need to be convinced that it's an actual error rather than just something like e.g. the first repaint being caused by a resize and the second being because of a focus change.

Certainly I wouldn't care if a window gets two repaints when it's first shown, or if it only happens occasionally. I might care if it's constantly doing unnecessary work while a window is being actively resized or dragged, but I'd have thought that even that would only become a noticable problem if you've got a dangerously slow paint method.


#11

Well, I gave you a sample that does absolutely nothing but print to stdout that it got a paint message.

On first appearance it paints twice.  If you resize it also paints twice.

Again, on OS X this does not happen; I see one paint per each of these events.  I don't know about other OSes, I don't have time right now to test on them.  But if this happens on a mobile device, it will be bad for performance as well as battery life.


#12

The sample code proves nothing at all.. When the window first appears there could easily be an extra repaint sent in the window initialisation, or when it gains focus to redraw the title bar, or many other reasons - but like I said above, who cares? An extra repaint once when the window is shown is irrelevant.

All these repaint messages go onto the system queue and may be merged, discarded, or re-scheduled by the OS, with countless other factors involved. And saying it happens twice on resizing is meaningless because maybe you moved the mouse twice, or maybe X windows sends another repaint when you finish dragging, or a dozen other possibilities that don't matter. You'll have to do better than this to convince me it's worth me spending time to investigate!