Arrays, recursion and crashes?

David Bovill david at openpartnership.net
Tue Aug 5 07:18:30 EDT 2008


Rev rarely crashes nowadays - but I've got it crashing regularly now :) It
seems to be in the same area that has caused me problems before so i thuoght
I would see if others have any similar experiences.

The context: I have an array which is used to store a "graph" = a linked
series of nodes. Each node is actually a key in the array, and the name of
the key is the name of a rev control. The elements of the array are other
named controls with may in turn link to other nodes in the array (named
controls) producing a graph. The recursive script walks the graph to delete
a node and anything that node links to that is not linked by other nodes -
that is it chops off any hanging branches.

This is the general purpose array handler to do this - the one that crashes:

on linkArray_DeleteNode @someArray, someKey, @alreadyDeleted
>     -- was "array_DeleteLinks"
>     -- Treats an array as a place to store graphs.
>     -- a recusive command
>
>     -- do a recursion safety check to avoid infinite loops
>     if someKey is among the lines of alreadyDeleted then return false
>     put someKey & CR after alreadyDeleted
>
>     -- delete the node someKey
>     put someArray [someKey] into childKeys
>     delete local someArray [someKey]
>     if childKeys is empty then return false
>
>     --  delete any links to the deleted node from other nodes
>     repeat for each key testKey in someArray
>         array_DeleteFromIndex someKey, testKey, someArray
>     end repeat
>
>     -- delete any child nodes of the deleted node (chop the branch off)
>     -- even if there are links from it
>     -- but not if other nodes link to it
>     put array_Reverse(someArray) into reversedArray
>
>     repeat for each line childKey in childKeys
>         -- lets work out what other nodes link TO the child
>         put reversedArray [childKey] into otherLinkingNodes
>         -- apart from someKey
>         line_Delete someKey, otherLinkingNodes
>
>         if otherLinkingNodes is empty then
>             -- recursively delete node
>             linkArray_DeleteNode someArray, childKey, alreadyDeleted
>         end if
>     end repeat
>     return true
> end linkArray_DeleteNode


Its hard to track down bugs that cause crashes and I can't post a stack as
the example uses a lot of libraries. Any thoughts?



More information about the use-livecode mailing list