Paint Event Failure??? : FOUND IT!!!

In my Tadpole App there is a Paint event for a Canvas that is basically the only control on a particular window

this paint event consists of

if showgrid then paint_grid g,zoom
drawobjects g,zoom

each of the two routines
paint_grid
drawobject
decide what needs to be drawn and at what scale on the graphics context.
I do it this way so I can use the same routines to create an external PNG, and for printing to the printer graphics context.
On macOS this works PERFECTLY

However… on Windows… it draws the grid… period
It does not draw the objects, although a program trace indicates it is calling the draw routines with the proper coordinates for every object
If I change the Zoom parameter, nothing changes (ie. the grid remains at what ever scale it was first drawn at)
But if I tell it to create a PNG file (which calls those same two routines, just passing a different graphic context)… THAT works

Bascially, no matter what, it seems that while the PAINT event does fire, and all the required routines are execute, the CANVAS never truly gets updated… and yes Invalidate is being called at appropriate times

I understand there are graphics Issues with Window 10, but I didn’t think they were “this bad”…

This sounds very bad, not as far as i can imagine.

How are your canvas doublebuffer and Erasebackgroud (on invalidate) set?
I’ll try to see if it results the same here.

Update : still have not tracked it down…
But for some reason when my app processes Database “A” … I get no image on the canvas
but when I process Database “B”… it works just fine…

I used the exact same database on both macOS and Win, and had the app log exactly what it was drawing and where it was drawing it… and the logs on both machines were nearly identical

  • object coordinates were slightly different +/- 2 or 3 pixels (understandable)
  • Windows called the PAINT event 3x to maxOS once (but the log output was identical for all 3 calls)

On both machines I have done clean compiles, erased any/all config data the app would have used…

FYI… this is via remote debugger… AND/OR moving the compiled exe from my Mac to Win
But it IS compiled on the MAC side

Does the DrawObjects code have ‘exception’ as the last line?
If so, an error will jump straight there and not continue.
If you build and test on Mac and get no errors on mac, it all works.
If an exception occurs only on Windows, you are not debugging it and don’t see the effect.
Put a messagebox after the Exception statement?

Maybe you are drawing to a point outside of the canvas’ dimensions? I think Mac and Windows differ ‘by one pixel’ in that regard

[quote=340241:@Jeff Tullin]Does the DrawObjects code have ‘exception’ as the last line?
If so, an error will jump straight there and not continue.
If you build and test on Mac and get no errors on mac, it all works.
If an exception occurs only on Windows, you are not debugging it and don’t see the effect.
Put a messagebox after the Exception statement?

Maybe you are drawing to a point outside of the canvas’ dimensions? I think Mac and Windows differ ‘by one pixel’ in that regard[/quote]

No exceptions, no errors… As I mentioned I put code to log every single step and both Win and macOS produce near identical logs…
As to drawing outside the canvas… doubtful, since the objects should cover the screen for one, and as I said, both indicate they are drawing the same objects at the same place in the same order…

Pretty much it is an array of classObjects where each does a

g.drawpicture xyz.image,xyz.xpos,xyz.ypos

I am trying to get a copy of Xojo2016r4.1 for Window install directly, so I can compile ON the Windows machine, and see if that makes a difference… Right now the compile is on the Mac.

Hi Dave,

Are the object that are being drawn pictures? It might be that it is not a picture type that Xojo can decode on Windows. Possibly try a few bitmaps or jpg’ just to see if it displays something on the screen.

Not sure if it will work, and it’s worth a try.

Good Point… but they are all images (picture objects) that are instantiated and drawn inside the app.
It does (simplified)

  • p=new picture(x,y)
  • g=p.graphics
  • g.draw stuff
  • store P in the object class (ie. XYZ in previous post)

So its not like I’m loading them from files … they don’t exist until the app runs and creates them… and their lifespan is the runtime of the app

Basically this is the Schema DIagram function in Tadpole… it reads the database Schema and creates an image for each table/view that contains the field info etc…
Eddies Electronics doesn’t work under Windows… but works fine on macOS
HOWEVER, Chinook works on both…

This strange…
here are the scenarios

  • run via remote debugger from my MAC to Win10
  • compile on Mac… transfer exe to Win10, and run
  • run in Xojo IDE under Windows
  • compile on WIndows Machine
    Done in both 32/64 bit to cover all bases

If I tell my app to load Eddie Electronic Database… the graphic window shows a grid and is otherwise “frozen”… athough the rest of the app run just fine
If I tell it to load Chinook (or any other DB for that matter)… everything works exactly as expected… Switch to Eddie (while still in the app)… nothing… switch back to Chinook… works…

Under macOS… it works for every database, every time.

Dave, how is the canvas configured, double-buffered, erase background, transparent etc.?
Have you tried different configs?

[quote=340391:@Carsten Belling]Dave, how is the canvas configured, double-buffered, erase background, transparent etc.?
Have you tried different configs?[/quote]
yup… every and all

like I’ve mentioned… if I load one database it works just fine… switching to a different one it doesnt…
yet unde macOS they all work
at the moment all of those are OFF

Ok… MORE STRANGE!!!

here is the ENTIRE Paint Event

#pragma Unused areas
#If Not DebugBuild
#pragma DisableBackgroundTasks
#pragma DisableBoundsChecking
#pragma StackOverflowchecking False
#pragma NilObjectChecking False
#EndIf

Dim x As Integer
Dim y As Integer
Dim gsize As Integer

g.ForeColor=&cffffff
g.fillrect 0,0,g.Width,g.Height

//
// Draw GRID
//
If showGRID And grid<>Nil Then 
  gsize =grid.width
  For x=0 To g.width Step gsize
    For y=0 To g.height Step gsize
      g.DrawPicture grid,x,y
    Next y
  Next x
End If
//
//
DRAW_THE_DIAGRAM(g,zoom,true)


// THIS SHOULD DISPLAY A WHITE # on RED BACKGROUND in upper corner
// shows find on macOS.... NEVER shows at all on Windows
g.TextSize=20
g.ForeColor=&cff0000
g.fillrect 0,0,200,30
g.ForeColor=&cffffff
g.DrawString format(Microseconds,"##########"),10,g.TextAscent+5

trace_log "EXIT PAINT"

The LAST few lines I added to indicate that I really had activity… it just shows the time change every update.

IT NEVER DISPLAYS ON WINDOWS… It is like it is aborting the paint event
BUT… the TRACE_LOG DOES send the exit message

The GRID draws ONCE… it should draw every time the “zoom” changes… which the logs are indicating is happening

Holds a Graphic Column with images (of electronic hardware). And the others ?

PROGRESS… of sorts

DRAW_THE_DIAGRAM(g,zoom,true)

if I comment out this one line… the PAINT event behaves as expected
well… the grid changes sizes, and the “microseconds” changes… :slight_smile:

Does Windows have a problem with passing the "G"raphics context as a parameter?

I filed a feedback report that reproduced issues with parameters that were being passed incorrectly on Windows and the issues were fixed. This could be another one of those edge cases with a parameter.

In general, I do not have problems passing graphics content as a parameter in Windows. I do it all the time in my programs.

it better not otherwise the IDE wouldnt work at all

[quote=340402:@Eugene Dakin]I filed a feedback report that reproduced issues with parameters that were being passed incorrectly on Windows and the issues were fixed. This could be another one of those edge cases with a parameter.

In general, I do not have problems passing graphics content as a parameter in Windows. I do it all the time in my programs.[/quote]

When was this issue “fixed”…???

Yeah I pass “G” around all the time… as a matter of fact for this program
the DRAW_THE_DIAGRAM routine is used for

  • the Screen – works fine on macOS, but not on Windows
  • the Printer - works fine on macOS… not sure about Windows
  • save to PNG - works fine on both

It just passes the graphic context to draw on, the zoom scale factor, and if it is on-screen (which just tells it if it should honor the scroll bars… and in this case that is 0,0 anyways)

but the way it is behaving it is almost as if “G” ends up referencing something/somewheree else
and at no point does my program ever attempt to “change” what “G” is, It comes from a Paint Event, a Picture or Printer dialog

I have a series of declares the draw dash/dot lines…
it seems that Windows 10 does not like them

Does anyone have a replacement that does work?
or am I using it wrong?

Const DashStyleSolid = 0
Const DashStyleDash = 1
Const DashStyleDot = 2
Const DashStyleDashDot = 3
Const DashStyleDashDotDot = 4
//Const DashStyleCustom = 5


pattern=DashStyleSolid // <---- IF I FORCE IT TO IGNORE THE DECLARES IT WORKS IN WINDOWS




If pattern<=DashStyleSolid Or pattern>DashStyleDashDotDot Then 
   // ** Solid Line is same regardless of Platform ** /
   g.DrawLine x1,y1,x2,y2
   Exit Sub
Else
#If TargetCocoa Then
      <....... cocoa declare removed to shorten the post.......>
#ElseIf TargetWindows Then
// ************************** //
// ** Windows Pattern Line ** //
// ************************** //
Dim pen As Integer
Dim n As Integer
Dim c As Color
Dim gpx As Integer
Dim mb As New MemoryBlock(4)

Declare Function GdipCreatePen1 Lib "GDIPlus" (c As Integer, width As Single, unit As Integer, ByRef p As Integer) As Integer
Declare Function GdipSetPenDashStyle Lib "GDIPlus" (pen As Integer, style As Integer) As Integer
Declare Function GdipCreateFromHDC Lib "GDIPlus" (hdc As Integer, ByRef g As Integer) As Integer
Declare Function GdipDrawLine Lib "GDIPlus" (g As Integer, pen As Integer, x1 As Single, y1 As Single, x2 As Single, y2 As Single) As Integer
Declare Function GdipDeletePen Lib "GDIPlus" (pen As Integer) As Integer
Declare Function GdipDeleteGraphics Lib "GDIPlus" (g As Integer) As Integer


c = g.ForeColor
mb.Byte(0) = c.blue
mb.Byte(1) = c.green
mb.Byte(2) = c.red
mb.Byte(3) = 255    // alpha = opaque
n = mb.Int32Value(0)
Call GdipCreatePen1(n, g.PenWidth, 2, pen)
Call GdipSetPenDashStyle(pen, pattern)
Call GdipCreateFromHDC(g.handle(Graphics.HandleTypeHDC), gpx)
Call GdipDrawLine(gpx, pen, x1, y1, x2, y2)
Call GdipDeletePen(pen)
Call GdipDeleteGraphics(gpx)
#EndIf
End If

declares into GDI or GDI+ are probably going to cause issues in 2016r4.1 and newer since we switched to Direct2D :stuck_out_tongue:
you probably need something completely different for this using Direct2D

you might be able to call and set up GDI / GDI+ yourself (since its no longer used we dont automatically initialize it) and that may work

Yeah… I have no idea where to find them, or how to translate to proper Xojo declares… especially since when I had asked about this a week or so ago, I was told (errorneously it seems), that while GDI+ wasn’t part of “Xojo”, the routines were still part of Windows and would be for some time…

Anyone have a Direct2d drop in equivalent for Xojo??

Not sure why Xojo only supports solid lines :frowning: (yeah I know… “Feature Request” :smiley: )

We no longer initialize GDI+ for you, so you’ll have to call GdiplusStartup somewhere before you can do any GDI+ related stuff.

and how does one do that?

I found this on an old post… but obviously it doesn’t work

 #if TargetWin32
    if not GdiPlus.Startup then
      MsgBox "GdiPlus is not supported, quitting now."
      Quit
    end if
  #endif