Ok… I have found the actual issue, and I think in the long run it is a bug in Xojo itself…
Turns out it only fails under a specific condition (which took a while to narrow down)
- the app must be using Retina/HDPI and be on a Retina screen
- the app must modifiy g.scaleX/Y … I did this in order to get a 1px wide line on a Retina screen. You will notice in the code I posted that I would multiple by the “current scale” … So I was storing the old scale, setting g.scalex=1 , drawing the line and restoring it to original. I remove that it works
SO HERE IS A VERSION THAT DOES WORK… I had to move the Scale math INSIDE the declares
#If TargetCocoa Then
Declare Sub CGContextSetLineDash Lib "Cocoa" ( context As Integer, phase As CGFloat, lengths As Ptr, count As UInt32)
Dim context As Integer = g.handle( g.HandleTypeCGContextRef )
#If Target32Bit
Const sizeOfSingle = 4
#Else
Const sizeOfSingle = 8
#EndIf
'
g.AntiAlias=False
lengths=Array(dash,spc)
//
lengthArray=New MemoryBlock(sizeOfSingle*(1 + UBound(lengths)))
For i = 0 To UBound(lengths)
#If Target32Bit
lengthArray.SingleValue(offset) = lengths(i)
#Else
lengthArray.DoubleValue(offset) = lengths(i)
#EndIf
offset = offset + sizeOfSingle
Next
//
CGContextSetLineDash context,0,lengthArray,lengths.Ubound+1
Dim oldScale As Double =g.scalex
g.scaleX=1 // THIS MUST HAPPEN AFTER THE FIRST DECLARE CALL
g.scaley=1
x1=x1*oldscale
y1=y1*oldscale
x2=x2*oldscale
y2=y2*oldscale
//
g.drawline x1,y1,x2,y2
//
g.scalex=oldScale
g.scaley=oldScale
// return graphic context to original state
CGContextSetLineDash context,0,Nil,0 ' solid line
g.AntiAlias=aa_flag
#EndIf