Reputation: 31
I am using panda3d and have came across an error. I have been looking for an answer for a while now, but I can't find one. Here is my error:
Known pipe types:
CocoaGraphicsPipe
(all display modules loaded.)
<__main__.MyGame object at 0x7ff3653696d0>
Known pipe types:
CocoaGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
File "3d.py", line 15, in <module>
ShowBase().run()
File "/Users/Munish/opt/anaconda3/lib/python3.8/site-packages/direct/showbase/ShowBase.py", line 423, in __init__
raise Exception("Attempt to spawn multiple ShowBase instances!")
Exception: Attempt to spawn multiple ShowBase instances!
here is my code:
from panda3d.core import loadPrcFile
from panda3d.core import ConfigPageManager
print( ConfigPageManager.getGlobalPtr())
loadPrcFile('Config.prc')
from direct.showbase.ShowBase import ShowBase
class MyGame(ShowBase):
def __init__(self):
super().__init__()
game = MyGame()
print(base)
ShowBase().run()
Here is my Conifg.prc:
win-size 1280 720
What am I doing wrong. Thank You in advance!
Upvotes: 1
Views: 1206
Reputation: 453
The problem here is that ShowBase is a Singleton. This means that only one instance of it, or any subclass of it, can be created in any one program. In your program, ShowBase is being instantiated twice, first one this line:
game = MyGame()
since MyGame
is a subclass of ShowBase.
The second instance of ShowBase is here:
ShowBase().run()
That last line should instead be:
game.run()
Upvotes: 1