FSM and PandaNode don't work together

Hello there!

I was updating my game to the latest Panda3D (from GitHub, bleeding edge). But whenever I loaded a specific class, Panda3D crashed. No info at all with spam enabled. I pinpointed it to the following line:

FSM.__init__(self, name)

I tried to init a single FSM class, and it worked. I realized that PandaNode and FSM weren’t working together.

Consider the following example:

from panda3d.core import PandaNode
from direct.fsm.FSM import FSM

class Test(PandaNode, FSM):
    
    def __init__(self):
        PandaNode.__init__(self, 'Test')
        FSM.__init__(self, 'Test')

Test()

Running the code leaves me with this traceback (don’t mind the first two calls): i.imgur.com/rLkJ2Fq.png

But if I switch the order… (This was my case, when P3D just simply crashed):

from panda3d.core import PandaNode
from direct.fsm.FSM import FSM

class Test(FSM, PandaNode):
    
    def __init__(self):
        FSM.__init__(self, 'Test')
        PandaNode.__init__(self, 'Test')

Test()

Just a crash. notify-level spam doesn’t log anything. i.imgur.com/HbRiTqx.png

I’m on Windows 10, using Python 2.7.11, 32-bit Panda3D build on 64-bit processor.

What can I do in this situation? Thanks.

Hmm, I see. Strange. The crash seems to occur in Python, not in Panda. Perhaps Python has issues inheriting from both a C++ and a Python class?

It’s worth noting that my previous Panda3D build was compiled on November 18 2015, it was working fine back then.

I’m trying out a different combination of C++ and Python class, when I have results, I’ll update this post

edit: Yeah, initing a Python class first and then a C++ class crashes the game. As for the other way around, PandaNode and FSM still don’t like each other. That’s my main concern, the

self.state = 'Off'

error

how about using c++ class through cython?

I’ll try a few different builds in a few days. Since we have a clear test case we should probably collect data from other environments first, before recommending an entire architecture change as a debugging step. The issue may be in platform specific builds, or an environment specific issue.

I am getting the same issue, but I am attempting to combine FSM, PandaNode, and DirectObject.

I am running the latest Panda3D 1.10.

The issue is that FSM defines a field self.state that conflicts with PandaNode which has a member called .state.

Is there a particular reason why you need a class to inherit from PandaNode and FSM? It seems a bit odd that you would use multiple base classes in this way.

It actually was originally written this way. I encountered this issue when I was attempting to upgrade from Panda3D 1.9.0 (yes, that old). Looks like I’m going to have to pull out the FSM from the class and make it just a variable. (self.fsm)

It might be better to inherit from FSM (which is required for the request methods to work), and to use composition for the PandaNode (which is a better idea anyway, because of the caveats with inheriting from C++ classes).

Can you drop some links where I can find out more about using composition for the PandaNode?

Thanks.

Composition (as opposed to inheritance) just means you’re storing the PandaNode as a member, such as self.node = PandaNode(...).

Oh, gotcha. Sorry for the confusion.