FillArea() stack overflow

Just starting out? Need help? Post your questions and find answers here.
User avatar
Mischa
Enthusiast
Enthusiast
Posts: 115
Joined: Fri Aug 15, 2003 7:43 pm

FillArea() stack overflow

Post by Mischa »

When i want to fill an image (size= 2598 x 10732)
with

Code: Select all

FillArea(_cx,_cy,-1,RGBA(0,0,0,0))
i become a
stack overflow or a silent ctd without debugger on. :(

My computer has 32 gigs ram and i have a geforce1050gtx.

Will the crash happens, cause the height of my image is more than 8192px ?
Smaller images working fine with FillArea().

Regards,
Mischa
User avatar
idle
Always Here
Always Here
Posts: 5042
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: FillArea() stack overflow

Post by idle »

This works on linux x64 and windows xp

Code: Select all

img = CreateImage(#PB_Any,2598,10732,32,0)
If img 
 If  StartDrawing(ImageOutput(img)) 
  FillArea(0,0,-1,RGB(0,255,0))
  StopDrawing() 
 EndIf 

  OpenWindow(0,0,0,800,600,"test")
  ImageGadget(1,0,0,800,600,ImageID(img))

  Repeat 
  Until WaitWindowEvent() = #PB_Event_CloseWindow 
EndIf
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
Lord
Addict
Addict
Posts: 847
Joined: Tue May 26, 2009 2:11 pm

Re: FillArea() stack overflow

Post by Lord »

Does it make any difference using a unicolor image
or a real picture with many details at the same size?
Image
User avatar
Mischa
Enthusiast
Enthusiast
Posts: 115
Joined: Fri Aug 15, 2003 7:43 pm

Re: FillArea() stack overflow

Post by Mischa »

Ok. I have playing around with the "bad" image that produces the stack overflow.
Also i've drawing a little red rect inside the same image and no bug will shown!?

Here you can see yourself. I think its a bug. :evil:
http://www.think-relative.de/transfer/fillarea_bug.zip
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: FillArea() stack overflow

Post by STARGÅTE »

I can confirm this stack overflow with your code and the "bad" image.
It seems like FillArea() uses internally a recursive algorithm for the filling.

As a work around, you can increase the stack size of your program:

Just save a file with:

Code: Select all

/STACK:8388608
and add this file to the compiler option panel: "linker options file"
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: FillArea() stack overflow

Post by Saki »

The fill functions of the GFX_Wizzard_BF
work with it, as well as with any images, limitless.
They are not based on PB functions.
A trick is used to keep the stack very small.
You can try it with the SpriteTool_BF from the download archive.
viewtopic.php?f=12&t=66927
地球上の平和
User avatar
Mischa
Enthusiast
Enthusiast
Posts: 115
Joined: Fri Aug 15, 2003 7:43 pm

Re: FillArea() stack overflow

Post by Mischa »

Thanks for reply stargate.

So, it IS a bug. 8)

Nice and simple workaround.
It works perfect. :D
Thank you!

And i don't want to skip the FillArea() Function, cause its lighting fast.
Much faster than direct pixel replacement with DrawingBuffer(). :!:

Regards,
Mischa
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: FillArea() stack overflow

Post by Saki »

Your image takes less than a second with Debgger for me with the BF Fill.
地球上の平和
User avatar
Mischa
Enthusiast
Enthusiast
Posts: 115
Joined: Fri Aug 15, 2003 7:43 pm

Re: FillArea() stack overflow

Post by Mischa »

Saki wrote:The fill functions of the GFX_Wizzard_BF
work with it, as well as with any images, limitless.
They are not based on PB functions.
A trick is used to keep the stack very small.
You can try it with the SpriteTool_BF from the download archive.
viewtopic.php?f=12&t=66927
Thanks for the hint. But this GFX Wizzard gizmo is monstrous. :shock:
1MB include file? Really? No, i want it smart and simple. 8)
I need ONE funtion, not hundreds. :cry: The include/example is also very confusing. :?
Maybe if there exists an include file with fill funtion only it would be interesting
as a worthy workaround...

But i think the native PureBasic FillArea() function should be fixed if this is possible.
This would be the best solution. :wink:
User avatar
Mischa
Enthusiast
Enthusiast
Posts: 115
Joined: Fri Aug 15, 2003 7:43 pm

Re: FillArea() stack overflow

Post by Mischa »

Saki wrote:Your image takes less than a second with Debgger for me with the BF Fill.
Original image (2598 x 10732):

~294 ms - debugger ON with PureBasic FillArea() :? (faster?)
~310 ms - debugger OFF with PureBasic FillArea()

~515 ms - debugger OFF with BucketFill()
User avatar
Saki
Addict
Addict
Posts: 830
Joined: Sun Apr 05, 2020 11:28 am
Location: Pandora

Re: FillArea() stack overflow

Post by Saki »

It is quite simple in itself.
BF() is the BF Base function, the multifunction core function.
BucketFill_BF() uses this core function and provides also automatically texture resizing.
Parameters you don't need can be left out.
The BF fill functions can also texture or make areas transparent.
For example, with the BF() function you can texture tile any background with a single line of code.
Furthermore it is possible to use Jpeg compressed SpriteSheets.
Create and extract sprite sheets.
And much more just with Sheets.
The behavior of the PB Fill function with debugger is known to me.
Also the tendency to a stack overflow.
BucketFill is optimal for SpriteSheets, it also doesn't use a stack.
The BF FloodFill function use a special mechanism to keep the stack very small and speed up.
Also, the BF FloodFill stack is dynamic, it has no limits.
地球上の平和
Post Reply