RefreshRect not firing Paint event

Hi, I have a Xojo 2016 project that uses the Window.KeyDown event to detect when a user presses a given key and if it matches the line:
RefreshRect( x, y, width, height )
causes the Paint event to refresh that part of the window.
However, in Xojo 2020 (r1.2) the same line does not fire the Paint event (the debugger just steps over it as though the line has been executed) and consequently that part of the window defined by x, y, width and height is not updated.
Anyone got any thoughts on why that would be? And what I have to do to get the Paint event to fire in response to the RefreshRect call?

Maybe Window.Invalidate(x, y, width, height, False) helps?

It should fire the paint event, did you try to put a breakpoint in there?

Yeah, tried that. It didn’t. )-:

Hi, Yes. It steps on to it and then off again (just like going over a Dim statement or setting a variable).

What os and what control are you calling this on, the window?

Hi, macOS 10.14.6. And yes the Window (as in Window.RefreshRect).
Also just tried Xojo r2 and get the same results.

Are you able to replicate this in a new test project with a simple bit of code on the window.paint?


and this on a button


OK. Thanks. That up dates the date / time. So the Paint event does get fired. I guess my problem is else where in the code? )-:

1 Like

It looks like in Xojo 2020 the Paint event is only fired when the current function / method ends; i.e. code after the RefreshRect but before the end of the function / method is executed before the Paint event, whereas in Xojo 2016, the Paint event is fired immediately after the RefreshRect and before any subsequent code in the function / method.
In order for my UI to update properly, I need the area declared by the RefreshRect to be updated before the next bit of code is executed, otherwise the UI doesn’t get updated properly.

paint is async.
you call a function: .invalidate(rect) or .refresh(rect) and the system will fire the paint event.

Paint is not asynchronous.

We ran into an issue where Refresh was no longer drawing immediately as it’s supposed to do. There’s a ticket somewhere in Feedback, but I can’t find it. I think this is what you’re running into.

Hi Tim, Perhaps it’s 55203 - Window.refresh does nothing in MacOS Mojave? Originally reported in March 2019 and marked as Reproducible (but I guess not fixed yet). There’s a suggestion that it works OK in Catalina, so perhaps I need to see about upgrading my macOS?

Paint is not asynchronous.

you can’t step trough the debugger and expect to get into the paint event from a method that’s calling the .Refresh(Rect) method.

That’s either a bug because of the issue where Refresh isn’t working as it’s supposed to or just a drawback of the debugger. To find out which, you’d have to launch a version of Xojo where Refresh isn’t broken.

Asynchronous means two things are happening at the same time. Paint code does not happen asynchronously (at the same time) or you’d be able to draw while your app did other things.

I tried putting a break in just after a refreshrect all the way back to 2016r1 in 10.14.x and I couldn’t get my simple example above to paint before it dropped into the debugger as I would expect.

Are you trying to refresh a control on the window by refreshing a portion of the window with the refreshrect?

1 Like

You are talking about cucurrency, that’s not existing in xojo normally. I’m talking about calling a method that the xojo main loop will pick up and execute (paint event)

In my test app with a colour property, in the Paint event I have:
If UBound( areas ) >= 0 Then
g.DrawingColor = c_Colour
g.FillRectangle( areas( 0 ).Left, areas( 0 ). Top, areas( 0 ).Width, areas( 0 ).Height )
End If
and in the KeyDown event:
c_Colour = RGB( 255, 0, 0 )
Self.RefreshRect( 30, 100, 10, 10 )
c_Colour = RGB( 0, 255, 0 )
Self.RefreshRect( 100, 30, 10, 10 )
c_Colour = RGB( 0, 0, 255 )
Self.RefreshRect( 180, 160, 10, 10 )
and with Xojo 2020 r2 when I press a key I get three squares at the co-ordinates defined by each of the RefreshRect calls but they are all blue. Not what I would expect. With Xojo 2016 r1, I get the three squares but they each have the colour defined in the KeyDown event. Which is what I would expect.
Searching Feedback for RefreshRect Paint event returns two items, neither of them are what I’m seeing.

Filed as 62843 in Feedback.

Sorry. I’m confused. Are you saying that you would expect to not go to the Paint event and drop into the debugger? Or that it should have gone to the Paint event, and then dropped into the debugger? I would have expected the latter. At least that is what I get in 2016 r1.
I’m trying to refresh several parts of the main window as a result of the user pressing a key.