Page 1 of 1
FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 2:45 pm
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)
Re: FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 2:53 pm
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,...
Re: FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 3:03 pm
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.
Re: FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 3:19 pm
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".
Re: FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 3:43 pm
by Marc56us
now I am able to reproduce the crash!
Not a bug: beware of typing errors: -50
F1
ClipOutput()
The (x, y) coordinates are always absolute [...]

Re: FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 6:39 pm
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 [...]
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?
Re: FillArea() inside ClipOutput() does not work
Posted: Fri Jul 22, 2022 8:51 pm
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.
Re: FillArea() inside ClipOutput() does not work
Posted: Mon Jul 25, 2022 9:55 am
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?
Re: FillArea() inside ClipOutput() does not work
Posted: Mon Jul 25, 2022 10:52 am
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
Re: FillArea() inside ClipOutput() does not work
Posted: Mon Jul 25, 2022 11:06 am
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.

Re: FillArea() inside ClipOutput() does not work
Posted: Mon Jul 25, 2022 12:07 pm
by Mijikai
That looks like a bug , FillArea() seems not to be correctly checked against the clipping rect.

Re: FillArea() inside ClipOutput() does not work
Posted: Mon Jul 25, 2022 12:31 pm
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.
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