Page 1 of 1

Crashing CF with a simple recursion

Posted: Fri Jun 16, 2006 6:06 am
by archangel77
Here is a simple shape:

Code: Select all

startshape S1
rule S1 {
	S2 {}
}
rule S2 {
	CIRCLE{}
	S2 {x 1.5 s .5}
}
This works perfectly. However, if I change the recursion in S2 to

Code: Select all

	S2 {x 1.5 s 1.5}
the program crashes (on Mac OS X). I know why - the program stops recursing when the shapes grow to small. My second example grows bigger and bigger, thus the size limit is never hit.

Are there some general programming rules for avoiding such mistakes, such as "Never scale up when recursing"?
An even better solution would be to throw a warning or stop rendering when a certain recursion limit is reached. Don't know if this is possible.

Posted: Fri Jun 16, 2006 10:30 pm
by MtnViewJohn
I admit that it is poor form to crash on this type of cfdg files. The general rule is that a recursive shape should always shrink the area of the shape. If you truly wish to grow recursively then you need to have a 'stopping' rule to terminate the recursion. Otherwise, as you saw, the recursion does not terminate and the program crashes.

Code: Select all

rule S2 {
    CIRCLE {}
    S2 { x 1.5 s 1.5 }
}
rule 0.01 S2 {}
The recursion will grow as long as the first rule is chosen and stop when the second rule is chosen.

If you want a growing recursion that has a fixed number of generation then you should use the new looping syntax:

Code: Select all

rule S2 {
    10* {x 1.5 s 1.5} CIRCLE {}
}

Posted: Thu Jun 22, 2006 10:41 am
by raimondious
Shouldn't the recursion stop when the already drawn shapes, not the one being generated, get too small? Are these sizes too hard to track?

Posted: Sun Jun 25, 2006 11:27 pm
by MtnViewJohn
No we don't stop when an already drawn shape shrinks below the drawing threshold. That seems like a good way to bail out on an ever-expanding cfdg file, but even ordinary cfdg files will have shapes that are drawn but later culled. We have thought about bailing out when the smallest drawn shape gets really small, well below the drawing threshold.