Crash on resize canvas whilst vector drawing

Just starting out? Need help? Post your questions and find answers here.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Crash on resize canvas whilst vector drawing

Post by DoubleDutch »

This code doesn't crash on Windows, but does on MacOS.

Code: Select all

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    CanvasGadget(0, 0, 0, 400, 200)
    LoadFont(0, "Impact", 20, #PB_Font_Bold)
    
    If StartVectorDrawing(CanvasVectorOutput(0))
    	ResizeGadget(0,0,0,500,300) ; <--- this will crash on macOS on the next draw, but doesn't crash windows
      VectorFont(FontID(0), 25)
      VectorSourceColor(RGBA(0, 0, 0, 80))
      Text$ = "The quick brown fox jumps over the lazy dog"
      
      For i = 1 To 6
        MovePathCursor(200 - VectorTextWidth(Text$)/2, 100 - VectorTextHeight(Text$)/2)
        DrawVectorText(Text$)
        RotateCoordinates(200, 100, 30)
      Next i

      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
Although this seems like a crazy example, this type of thing can happen if a window is resized when the window resize event is bound to something that resizes the gadgets.

Windows seems to work fine, but macOS doesn't like it can crashes with a memory error on the next draw after the resize.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
mk-soft
Always Here
Always Here
Posts: 5402
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB v5.74b4 - crash on resize canvas whilst vector drawin

Post by mk-soft »

I don't see it as a bug, as a rule that you cannot use ResizeGadget within StartDrawing.

It changes the memory (handle) for the graphic output to ResizeGadget and therefore the memory (handle) of CanvasVectorOutput is no longer valid.

With Window 10 it does not crash, but the output fails.
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
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PB v5.74b4 - crash on resize canvas whilst vector drawin

Post by DoubleDutch »

I know, but these should be a system in place to cancel out the drawing in macOS - just like Windows. This will happen more as programs start to use the bounding of events.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
mk-soft
Always Here
Always Here
Posts: 5402
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB v5.74b4 - crash on resize canvas whilst vector drawin

Post by mk-soft »

Now I don't know what you mean by events, in the context of drawing.

Even if windows does not crash, the Graphic output runs into nirvana, and it can lead to undefined states.
Events are always processed sequentially in the MainScope (main program). Even if they are triggered by PostEvent.

Perhaps means this events ...

Code: Select all


Procedure DrawGadget()
  Protected dx.d, dy.d, ScaleX.d, ScaleY.d
  dx = GadgetWidth(0)
  dy = GadgetHeight(0)
  
  ScaleX = dx / 400.0
  ScaleY = dy / 200.0
  
  If StartVectorDrawing(CanvasVectorOutput(0))
    ScaleCoordinates(ScaleX, ScaleY)
    
    ; Background
    AddPathBox(0.0, 0.0, 400.0, 200.0)
    VectorSourceColor(#White | $FF000000)
    FillPath()
    
    ; Border
    AddPathBox(10.0, 10.0, 380.0, 180.0)
    VectorSourceColor(#Blue | $FF000000)
    StrokePath(2.0)
    
    ; Boxes
    AddPathBox(50, 50, 200, 50)
    AddPathBox(150, 75, 200, 50)
    VectorSourceColor(RGBA(255, 0, 0, 255))
    StrokePath(4)
    
    StopVectorDrawing()
  EndIf
EndProcedure

Procedure UpdateWindow()
  ResizeGadget(0, #PB_Ignore, #PB_Ignore, WindowWidth(0), WindowHeight(0))
EndProcedure

If OpenWindow(0, 0, 0, 400, 200, "VectorDrawing", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  CanvasGadget(0, 0, 0, 400, 200)
  
  DrawGadget()
  
  BindGadgetEvent(0, @DrawGadget(), #PB_EventType_Resize)
  BindEvent(#PB_Event_SizeWindow, @UpdateWindow())
  
  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
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: PB v5.74b4 - crash on resize canvas whilst vector drawin

Post by DoubleDutch »

You can bind an event to a procedure - so when the resize event is triggered, the procedure is called.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply