child is already inserted in a tree

Assertion 'child->_nextSibling == NULL' failed. child is already inserted in a tree Assertion 'child->_parent == NULL' failed. child is already inserted in a tree

These messages began to appear recently in a code that has been 'working' for many years. I guess that I must have done something wrong, but I do not know where to start looking to see why this error is occurring.

I guess it has something to do with SCNode and Scene Kit, but any pointers would be gratefully received.

The two messages may repeat 20-200 times while launching, and occasionally the program hangs.

Advice on the net is to create a cut down version prior to creating a TSI. Easier said than done, given that this is a large program. And somehow one is supposed to reduce the problem to <250 lines which seems utterly infeasible in this case. Nevertheless, some days and many hours later, the program is vastly reduced, but still there are >150 files to comb through.

The useful outcome of this work however is that I can characterise the 'phenomonology' that surrounds the appearance of these message strings. Sometimes after a rebuild, the cut down program must be launched sequentially several times before the messages begin once again to appear. I suppose therefore that somewhere in the program worker threads are launched that SceneKit cannot manage properly, or that there is something I am doing that prepares the ground for thread conflict. I do not know.

Some days later, the tedium of cutting down a massive project is finally rewarded. The code was using a method of opening a document that perhaps is no longer supported?

// problem somehow associated with this line of code // maybe the GPU is not cleaned out properly??? [self openNewDocumentIfNeeded];

Once that line was commented out, the problem went away.

In case one might spend more time wondering why .... ? ... then here is the offending code segment

// this code segment is from https://stackoverflow.com/questions/7564290/why-isnt-applicationshouldopenuntitledfile-being-called

  • (void) openNewDocumentIfNeeded {

    // Get the recent documents

    NSDocumentController * controller = [NSDocumentController sharedDocumentController];

    NSArray * documents = [controller recentDocumentURLs];

    // how many documents are in the recent list

    // .. the most recent document added is at the bottom of the list

    // ... but somehow I've noticed that the order of documents in the list can change

    int nRecents = (int)[documents count];

    // If there is a recent document, try to open it.

    if ( nRecents > 0 ) {

      NSError * error = nil;
    
      NSURL * url = [documents objectAtIndex:(nRecents-1)];
    
      [[NSDocumentController sharedDocumentController] openDocumentWithContentsOfURL:url display:YES completionHandler:(void (^)(NSDocument * document, BOOL documentWasAlreadyOpen, NSError * error ) ) ^{
    
          ;
      }];
      
      // If there was no error, then prevent untitled from appearing.
      if ( error == nil ) {
          if ( nRecents > 0 ) {
              return;
          }
      }
      
    

    }

    // Open an untitled document what if there is no document. (restored, opened).

    if ( nRecents == 0 ){

      [[NSDocumentController sharedDocumentController] openUntitledDocumentAndDisplay:YES error: nil];
    

    }

}

child is already inserted in a tree
 
 
Q