[PD] deadly dangling scalars

Krzysztof Czaja czaja at chopin.edu.pl
Wed Sep 26 12:01:40 CEST 2001


hi,

whoever attempted closing /doc/5.reference/pointer.pd (is there
anyone that curious?), would have probably noticed a strange
behaviour:

1. Closing the main patch with a data-subpatch window left open
(as it was loaded) crashes Pd.

2. Closing data-subpatch window first, then closing the main patch
does not crash Pd.

After some digging I found that:

1. In template_free() there is a relevant comment:
``figure out how to get rid of data having this template''.
It is marked `LATER'.

2. If a template is destroyed first -- before destruction of those
scalars that use this template -- and if the canvas holding those
scalars has its window open, then Pd dies.  The reason: freeing
a visible canvas means calling vis-routines of all objects in this
canvas -- scalar_vis() is called, while there is no template.

3. Since what is deadly here is the scalar_getbasexy() call, Pd
dies quietly, with no error message printed.  Adding an early
check into scalar_vis() would work as a temporary safeguard:

     float basex, basey;
+    if (!glist) return;
     scalar_getbasexy(x, &basex, &basey);
     if (!glist) bug ("scalar_vis");
 
4. This safeguard would not prevent scalar_free() from complaining
``scalar: couldn't find template'', but it is much lesser evil
than crashing.

5. This crash is yet another case of order dependence horror.
If data-canvas had been stored within pointer.pd file before
tamplate-canvases, no crash would have occured.

Krzysztof



More information about the Pd-list mailing list