Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recursion limit?
#1
Is there a limit to the number of recursions that QB64PE can handle? The code below works well with a circle the radius of 50, but increase the radius to 100 and the program will crash part way through.

Also, I figured out why the IDE was using so much RAM (256MB as I reported in another thread). Every crash of this program increases the IDE RAM usage.

Keep in mind the code below is just me playing around. It's not optimized at all or debugged in any way. Just me experimenting.

Code: (Select All)
OPTION _EXPLICIT

DIM Image AS LONG
DIM x AS INTEGER
DIM y AS INTEGER


Image = _NEWIMAGE(800, 600, 32)
SCREEN Image
MemCLS Image, _RGB32(255, 255, 255)

CIRCLE (399, 299), 50, _RGB32(0, 0, 0) ' recursion works at radius 50, fails at radius 100

FloodPaint 399, 299, _RGB32(255, 0, 255), _RGB32(0, 0, 0) ' recursive paint



SUB FloodPaint (x AS INTEGER, y AS INTEGER, c AS _UNSIGNED LONG, b AS _UNSIGNED LONG)

    ' x,y - paint location
    ' c   - paint color
    ' b   - border color

    DIM p AS _UNSIGNED LONG ' pixel color

    STATIC Iterations AS LONG ' the number of iterations

    IF x = -1 OR y = -1 OR x = _WIDTH(_DEST) OR y = _HEIGHT(_DEST) THEN EXIT SUB
    p = POINT(x, y)
    IF p = b OR p = c THEN EXIT SUB
    PSET (x, y), c
    Iterations = Iterations + 1

    ' Just some code to show what's going on and slow things down a bit

    LOCATE 1, 1
    PRINT x, y, Iterations
    _DELAY .001

    ' Check neighboring pixels

    FloodPaint x - 1, y, c, b
    FloodPaint x + 1, y, c, b
    FloodPaint x, y - 1, c, b
    FloodPaint x, y + 1, c, b

    Iterations = Iterations - 1

END SUB


FUNCTION xyOFFSET%& (i AS LONG, x AS INTEGER, y AS INTEGER)

    ' Calculates the pixel memory address offset location within an image given the x,y coordinate pair
    '
    ' i   - image handle
    ' x,y - pixel coordinate

    $CHECKING:OFF
    IF (i = 0 OR i < -1) AND _PIXELSIZE(i) = 4 THEN '      valid 32bit image?
        xyOFFSET%& = y * _WIDTH(i) * 4 + x * 4 ' yes, calculate pixel offset location
    END IF
    $CHECKING:ON

END FUNCTION



SUB MemCLS (i AS LONG, c AS _UNSIGNED LONG)

    ' Clears an image with provided color
    '
    ' i - image handle
    ' c - 32bit color

    DIM m AS _MEM

    $CHECKING:OFF
    IF (i = 0 OR i < -1) AND _PIXELSIZE(i) = 4 THEN ' valid 32bit image?
        m = _MEMIMAGE(i)
        _MEMFILL m, m.OFFSET, m.SIZE, c
        _MEMFREE m
        $CHECKING:ON
    END IF

END SUB
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Recursion limit? - by TerryRitchie - 03-12-2024, 02:55 AM
RE: Recursion limit? - by SMcNeill - 03-12-2024, 03:56 AM
RE: Recursion limit? - by TerryRitchie - 03-12-2024, 05:49 AM
RE: Recursion limit? - by Jack - 03-12-2024, 11:36 AM
RE: Recursion limit? - by SMcNeill - 03-12-2024, 12:03 PM
RE: Recursion limit? - by GareBear - 03-12-2024, 02:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Recursion Limit bplus 14 2,518 10-17-2025, 07:46 PM
Last Post: a740g
  Feature Request: Limit Scope of a "Find" and "Change" hanness 5 717 06-21-2025, 11:21 PM
Last Post: SMcNeill
  Stack size limit for If/Then statements? JamesAlexander 20 3,626 01-31-2024, 06:21 PM
Last Post: Kernelpanic

Forum Jump:


Users browsing this thread: 1 Guest(s)