FillArea() inside ClipOutput() does not work

Just starting out? Need help? Post your questions and find answers here.
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

FillArea() inside ClipOutput() does not work

Post by nicoh »

Hello,

I guess there is a bug in FillArea() when the drawing output is clipped.

Code: Select all

EnableExplicit

OpenWindow(0, 0, 0, 400, 400, "FillArea() Bug", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 400, 400)

If StartDrawing(CanvasOutput(0))
  Box(0, 0, 400, 400, #Green)
  ClipOutput(100, 100, 200, 200)  ; Clips the output to a 200x200 square
  FillArea(50, 50, #Blue, #Blue)  ; The 200x200 square should be painted blue (but nothing is painted blue)
  UnclipOutput()
  StopDrawing()
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Shouldn't there be an inner square drawn in blue?

If you remove the "ClipOutput()", the whole window is painted blue.
So when clipping the output, there should be an inner square painted blue? Where is it?

In my real program (which is a bit more complex than this sample program) the program even crashes at this point with a "random" memory error or the executable ends unexpectedly. Unfortunately I could not reproduce this crash specifically in a sample program, but I am relatively sure that the crash comes from FillArea(). If I comment out FillArea() in my real program, it no longer crashes.

EDIT: Now I am able to reproduce the crash in a sample program. See posting below.

Maybe someone who has insight into the implementation of FillArea() can check this?

// Moved from "Bugs - Windows" to "Coding Questions" (Kiffi)
Last edited by nicoh on Fri Jul 22, 2022 3:20 pm, edited 1 time in total.
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: FillArea() inside ClipOutput() does not work

Post by Mijikai »

No Bug!

From the help:
The drawing origin is not modified by a call to this function. To make all drawing relative to the upper left corner of the clipping box, a separate call to SetOrigin() must be made if this is desired
Either use SetOrigin() or Fill(100,100,...
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: FillArea() inside ClipOutput() does not work

Post by nicoh »

No Bug!

From the help: [...]
I know the origin (50,50) is outside the clipped area.

when replacing FillArea() with Box(0, 0, 400, 400, #Blue) the inner square is still painted blue, even if the (0,0) point is outside the clipped area.
Same thing when drawing lines, circles etc ... every drawing operation which starts outside the clipped area is still drawn inside the area.

So why doesn't the same thing happens to FillArea() ?
I guess this is a bug or at least inconsistent.
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: FillArea() inside ClipOutput() does not work

Post by nicoh »

Hello,

now I am able to reproduce the crash!

Code: Select all

EnableExplicit

OpenWindow(0, 0, 0, 400, 400, "FillArea() Bug", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 400, 400)

If StartDrawing(CanvasOutput(0))
  
  ClipOutput(248,-50,30,54)
  FillArea(277,3,$FF,$FF)
  UnclipOutput()
  
  ClipOutput(248,68,30,54)
  FillArea(277,121,$FF,$FF)
  UnclipOutput()
  
  ClipOutput(248,127,30,54)
  FillArea(277,180,$FF,$FF)
  UnclipOutput()
  
  StopDrawing()
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
This code crashes with "Invalid memory access".
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: FillArea() inside ClipOutput() does not work

Post by Marc56us »

now I am able to reproduce the crash!

Code: Select all

ClipOutput(248,-50,30,54)
Not a bug: beware of typing errors: -50
F1
ClipOutput()
The (x, y) coordinates are always absolute [...]

:wink:
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: FillArea() inside ClipOutput() does not work

Post by nicoh »

Marc56us wrote: Fri Jul 22, 2022 3:43 pm Not a bug: beware of typing errors: -50
F1
ClipOutput()
The (x, y) coordinates are always absolute [...]

:wink:
Okay, that's a calculation error in my program. The value should not be smaller then 0. I agree.
But still ... there should not be a Memory Error since I don't do any memory operations?
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: FillArea() inside ClipOutput() does not work

Post by Mijikai »

In order to be fast some drawing functions wont perform boudary checks, so you might end up drawing in arbitrary memory which is bad.
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: FillArea() inside ClipOutput() does not work

Post by nicoh »

So, I added boundary checks to my programm but it still crashes with a memory error.

Code: Select all

EnableExplicit

OpenWindow(0, 0, 0, 800, 800, "FillArea() Bug", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 800, 800)

If StartDrawing(CanvasOutput(0))
  
  ClipOutput(248, 0, 30, 46)
  FillArea(277, 9, $FF0000, $FF0000)
  UnclipOutput()
  
  ClipOutput(248, 51, 30, 54)
  FillArea(277, 68, $FF0000, $FF0000)
  UnclipOutput()
  
  StopDrawing()
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Any ideas?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: FillArea() inside ClipOutput() does not work

Post by RASHAD »

Hi

Code: Select all

EnableExplicit

OpenWindow(0, 0, 0, 800, 800, "FillArea() Bug", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
CanvasGadget(0, 0, 0, 800, 800)

If StartDrawing(CanvasOutput(0))
  
  ClipOutput(248, 100, 30, 54)
  FillArea(277, 110, $FF0000, $FF0000)
  UnclipOutput()
  
  ClipOutput(248, 50, 30, 46)
  FillArea(277, 55, $0000FF, $0000FF)
  UnclipOutput()
  
  ClipOutput(248, 0, 30, 46)
  FillArea(277, 9, $00FF00, $00FF00)
  UnclipOutput()
  
  StopDrawing()
EndIf

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: FillArea() inside ClipOutput() does not work

Post by nicoh »

This works:

Code: Select all

  ;A
  ClipOutput(248, 100, 30, 54)
  FillArea(277, 110, $FF0000, $FF0000)
  UnclipOutput()
  
  ;B
  ClipOutput(248, 0, 30, 46)
  FillArea(277, 9, $00FF00, $00FF00)
  UnclipOutput()
But when swapping, it crashes.

Code: Select all

  ;B
  ClipOutput(248, 0, 30, 46)
  FillArea(277, 9, $00FF00, $00FF00)
  UnclipOutput()
  
  ;A
  ClipOutput(248, 100, 30, 54)
  FillArea(277, 110, $FF0000, $FF0000)
  UnclipOutput()
I don't get it, sorry. :?: :?:
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: FillArea() inside ClipOutput() does not work

Post by Mijikai »

That looks like a bug , FillArea() seems not to be correctly checked against the clipping rect. :o
nicoh
User
User
Posts: 26
Joined: Thu Sep 19, 2019 10:44 am

Re: FillArea() inside ClipOutput() does not work

Post by nicoh »

Mijikai wrote: Mon Jul 25, 2022 12:07 pm That looks like a bug , FillArea() seems not to be correctly checked against the clipping rect. :o
So someone could move this post back to "bug reports" please?

Edit: Created new bug report: https://www.purebasic.fr/english/viewtopic.php?t=79568
Post Reply