Crashing CF with a simple recursion

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
archangel77
Posts: 1
Joined: Fri Jun 16, 2006 5:47 am

Crashing CF with a simple recursion

Post 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.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post 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 {}
}

raimondious
Posts: 12
Joined: Thu Apr 13, 2006 3:45 pm

Post 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?

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post 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.

Post Reply