ShowBase's .destroy() doesn't destroy ShowBase

A simple unit test illustrating the issue:

import unittest
from direct.showbase.ShowBase import ShowBase

class TestPanda(unittest.TestCase):
    def test_panda(self):
        self.base = ShowBase()
        self.base.destroy()
        del(self.base)
        self.base = ShowBase()
        self.base.destroy()
        del(self.base)
     
    """ Resulting error:
     
    Traceback (most recent call last):
     File "map_test.py", line 55, in test_panda
       self.base = ShowBase()
     File "C:\Panda3D-1.9.0-x64\direct\showbase\ShowBase.py", line 316, in __init__
     
       raise StandardError, "Attempt to spawn multiple ShowBase instances!"
    StandardError: Attempt to spawn multiple ShowBase instances!
     
    """

This is very unintuitive, and additionally also a problem for unit tests that need to create a ShowBase since it requires ugly hacks passing the ShowBase along to the next test. Therefore, a fix would be nice.

  • 1

This has come up before, and explanations have been given as to why this is not done, but I would still love to see it happen, for exactly the same reasons. See this link for a possible to work around:
[Destroying and re-creating ShowBase)

cheers,
Maria

I’m working on it.
bugs.launchpad.net/bugs/1339701

Awesome, thanks!

Couldn’t load model after recreate ShowBase

# coding: utf-8

import unittest
import os
from direct.showbase.ShowBase import ShowBase


class TestShowBase(unittest.TestCase):

	def test_load_model(self):
		show_base = ShowBase()
		self.assertTrue(os.path.exists("/usr/share/panda3d/models/panda.egg.pz"))
		show_base.loader.loadModel("/usr/share/panda3d/models/panda.egg.pz")
		show_base.destroy()
		del show_base
		show_base = ShowBase()
		self.assertTrue(os.path.exists("/usr/share/panda3d/models/panda.egg.pz"))
		show_base.loader.loadModel("/usr/share/panda3d/models/panda.egg.pz")
		show_base.destroy()
		del show_base


if __name__ == '__main__':
	unittest.main()

:loader(error): Couldn’t load file /usr/share/panda3d/models/panda.egg.pz: does not exist.

Error
Traceback (most recent call last):
File “/home/igor/work/pg/src/test/test_app.py”, line 18, in test_load_model
show_base.loader.loadModel("/usr/share/panda3d/models/panda.egg.pz")
File “/usr/share/panda3d/direct/showbase/Loader.py”, line 170, in loadModel
raise IOError, message
IOError: Could not load model file(s): [’/usr/share/panda3d/models/panda.egg.pz’]

:util(error): Could not write index file: /home/igor/.panda3d/cache/index-cdf506.boo
:util(error): Could not write to the Bam Cache. Disabling future attempts.

I believe this issue has been fixed in the development version of Panda.