PB v6.21 DrawText Outside of Visible Range

Post bugreports for the Windows version here
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

PB v6.21 DrawText Outside of Visible Range

Post by mk-soft »

On Windows, this leads to a crash. On macOS and Linux it works and the new x Position returned correctly.
With PB v6.20, this also works on Windows.

Code: Select all

If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
  Debug DrawText(-50, 400, "B!", $123456)
  StopDrawing() 
EndIf
[22:11:44] Waiting for executable to start...
[22:11:43] Executable type: Windows - x64 (64bit, Unicode)
[22:11:44] Executable started.
[22:11:44] [ERROR] Line: 2
[22:11:44] [ERROR] Invalid memory access. (write error at address 1957730877440)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB v6.21 DrawText Outside of Visible Range

Post by mk-soft »

Workaround until this is repaired :wink:

Update v1.01.2

Code: Select all

;-TOP

;- *** PB v6.21 Workaround DrawText by mk-soft, v1.01.2, 03.07.2025 ***

; Link: https://www.purebasic.fr/english/viewtopic.php?t=87121

CompilerIf #PB_Compiler_OS = #PB_OS_Windows And #PB_Compiler_Version = 621
  Procedure.d _FixDrawText(x.d, y.d, Text$, FrontColor=-1, BackColor=-1)
    Protected r1.d, dx.d
    dx = TextWidth(Text$)
    If x + dx <= 0.0
      ;Debug "No DrawText"
      ProcedureReturn x + dx
    EndIf
    If FrontColor <> -1
      If BackColor <> -1
        r1 = DrawText(x, y, Text$, FrontColor, BackColor)
      Else
        r1 = DrawText(x, y, Text$, FrontColor)
      EndIf
    Else
      r1 = DrawText(x, y, Text$)
    EndIf
    ProcedureReturn r1
  EndProcedure
  
  Macro DrawText(x, y, Text, FrontColor=-1, BackColor=-1)
    _FixDrawText(x, y, Text, FrontColor, BackColor)
  EndMacro
CompilerEndIf

;- ***

If OpenWindow(0, 0, 0, 200, 200, "2DDrawing Beispiel", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateImage(0, 200, 200) And StartDrawing(ImageOutput(0))
    DrawingMode(#PB_2DDrawing_Transparent)
    Box(0, 0, 200, 200, RGB(255, 255, 255))
    For i = 1 To 30
      DrawText(Random(300)-100, Random(200), "Hello World!", RGB(Random(255), Random(255), Random(255)))
    Next i
    StopDrawing() 
    ImageGadget(0, 0, 0, 200, 200, ImageID(0))
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply