runtime error by setting material

Hello there,

when i run my program in VisualStudio 2008 it crashes unexpected. with a little luck i managed to take a lastminute screenshot of the console window. the console output is the following:

known pipe types:
(all display modules loaded.)
Loading planet.bam
Assertion failed: _ref_count == 0 || _ref_count == local_ref_count at line 129 of c:\panda3d-1.7.0\built\include\referenceCount.I
Loading planet.bam

This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information

the context: i have a model of an icosphere/icosahedron called planet.bam. i load it for two times in my code. once, for a planet represented by an icosphere in my scene. twice, for each triangle on the icosphere to place it there in a smaller version.
in both cases i assign a new material to the nodes.
this happens one time for the planet and later N times in a for-loop for every normalized positionvector of a triangle of the icosphere.

in fact first turn in the for-loop works fine, but the second turn the debugger shows me my program crashes assigning the material to my node.

its hard for me to explain the information you possibly might need, cause my program structure is a bit more complicated. but I hope that is enough for now.

First, you don’t need to rely on luck to capture the termination message. You should run your program from the console window and then it won’t go away when the program terminates.

As to the error itself, it looks like you are doing something wrong with the reference counting system. It’s very important to get this right. Make sure that whenever you store a pointer to a Panda object that inherits from ReferenceCount (and most Panda objects do), you store it in a PT(ObjectType) pointer instead of an ObjectType * pointer.


Thank you, thats a good advice. Can you give me an example for the Material-class? How can i fix that:

PT(Material) myMat;

NodePath myNP;

myNP.set_material(&myMat) // expects Material* instead of PT(Material) --> compilererror

It refers to the example in my first question, where i had problems assigning materials.

This should work fine:

PT(Material) myMat = new Material; 

NodePath myNP; 


The problem was that you didn’t assign myMat to be any material object. You were passing set_material an uninitialised pointer.