problem with flattenStrong

I’m having a problem getting flattenStrong to work. I can reproduce the problem with the following code on 64bit vista and ubuntu 8.10:

import direct.directbase.DirectStart
 
base.setFrameRateMeter(True)
cellRoot = render.attachNewNode("cellRoot")
for x in range(16):
   for y in range(16):
      b = loader.loadModel("box")
      b.reparentTo( cellRoot )
      b.setPos( x,y,0 )
render.flattenStrong()
run()

This causes the application to crash with the following output:

Assertion failed: _node_ref_count > 0 at line 233 of c:\p\panda3d-1.5.4\built\include\nodeCachedReferenceCount.I
Assertion failed: _prev == (LinkedListNode *)NULL && _next == (LinkedListNode *) NULL at line 94 of c:\p\panda3d-1.5.4\built\include\linkedListNode.I

If I switch it to flattenMedium, the application crashes with no output (segfault on ubuntu). However, flattenLight works fine.

Any help would be greatly appreciated.

Hmm. Does it also crash if you just call cellRoot.flattenStrong() instead of render.flattenStrong()? Remember that render also includes the camera, and inadvertently flattening the camera has occasionally been known make bad things happen. Of course, it’s not supposed to crash in any case.

David

On a sidenote, this also won’t really flatten anything since there will be model roots in the box.
Try this:

      b = loader.loadModel("box").getChild(0)

Or, use the clearModelNodes function.

Yes it does.

I’m aware- just wanted to minimize the LOC in the example I gave. Thanks though.

Really? Are you sure? It doesn’t crash for me when I flatten cellRoot. I do see the crash on render, though.

I don’t know what you mean by LOC, but if you mean you wanted to apply the transforms to the vertices and remove them from the nodes, then flattenLight() is sufficient for this purpose.

The three flattens are:

flattenLight(): remove transforms and state changes (where possible) from the nodes, and apply them down to the vertices, or at least the Geoms.

flattenMedium(): do the above, then also remove some redundant nodes that are not important to the hierarchical structure. For instance, it will shorten a linear chain of nodes into a single parent-child node pair, but it will not combine sibling nodes.

flattenStrong(): do the above, but also combine sibling nodes, and furthermore aggressively attempt to combine Geoms into a single Geom where possible.

David

I retried it to be sure and it apparently does work (perhaps I didn’t save my changes when I tried it earlier?).

Sorry, I meant I was trying to minimize the number of lines of code in the example I gave to simplify the problem.

Thanks for the help.