Inform - Support - Patches

About Patches  

Compiler  
Library  

DM4 Errata  

Issue L61032

IndirectlyContains() fails with dynamic objects
Submitted by: Roger Firth     Appeared in: Library 6/10 or before     Fixed in: Library 6/11
Problem

When you specify a Class which supports creation of objects at run-time, the compiler actually pre-allocates the objects -- including one spare to support recreate() -- as children of the Class itself. This parentage leads to problems with IndirectlyContains(). For example, this code:

  Class   Thing(3);
  ...
  objectloop (x ofclass Thing && IndirectlyContains(location,x))
      print (name) x, "^";

causes this run-time error:

  [** Programming error: tried to find the "parent" of Thing **]
  [** Programming error: tried to find the "parent" of Thing **]
  [** Programming error: tried to find the "parent" of Thing **]
  [** Programming error: tried to find the "parent" of Thing **]
Solution

This is the coding of IndirectlyContains:

  [ IndirectlyContains o1 o2;
    while (o2~=0)
    {   if (o1==o2) rtrue;
        o2=parent(o2);
    }
    rfalse;
  ];

and the fix adds an additional test:

  [ IndirectlyContains o1 o2;
    while (o2~=0)
    {   if (o1==o2) rtrue; if(o2 ofclass Class) rfalse;
        o2=parent(o2);
    }
    rfalse;
  ];

An alternative (and arguably better) solution would be to fix objectloop so that it omits the pre-allocated objects (which, after all, don't yet exist in any real sense). A game which really did want to loop through them could use something like:

  objectloop (x in Thing) ...


Last updated 2 May 2008. The librarian in charge of this page is Roger Firth. Please email any comments, suggestions or corrections to roger@firthworks.com.