Librocket - cleanup

Hi,

Having some issues recreating a librocket region after removing it. Using todays buildbot version.

Error:

:rocket(warning): Failed to create context 'pandaRocket', context already exists.
....
  File "C:\dev\Panda3D-1.8.0\samples\rocket-sample\test.py", line 30, in do
    self.r = RocketRegion.make('pandaRocket', base.win)
AssertionError: _context != NULL at line 52 of c:\buildslave\dev_sdk_win_i386\build\panda3d\panda\src\rocket\rocketRegion.cxx

Code:


from panda3d.rocket import *
from direct.directbase import DirectStart

class test():

	def __init__(self):

		self.r = ''

		self.do()

	def cleanup(self):
		del(self.context)
		base.win.removeDisplayRegion(self.r)
		del(self.r)


	def do(self):
		if(self.r):
			self.cleanup()

		self.r = RocketRegion.make('pandaRocket', base.win)
		self.r.setActive(1)
		self.context = self.r.getContext()

		ih = RocketInputHandler()
		base.mouseWatcher.attachNewNode(ih)
		self.r.setInputHandler(ih)


test = test()

base.accept('f1-up', test.do)

run()

Press ‘F1’ to generate the error.

Any hints?

I supose I could just have one rocket region for the life of the application, but not sure if that is best practice, or if its better to destory/recreate when required.

You can use one rocket region for the lifetime of your game/application. You could also consider using something different for your GUI: libRocket development is dead, unfortunately. There are some major bugs and nobody cares about :-/

Hmm, ok, will just have to pass the rocket region reference around :slight_smile:

Well, for myself libRocket is very fast to create the UI, much faster then Direct. I can’t see a better stable alternative at present.

Theres some activity on github: github.com/lloydw/libRocket/pulls so potentially you could build a custom version of rocket with some of those bug fixes.

Well, I’ve tested libRocket cleanups a bit more, and I’m not too sure but there seems to be a memory leak in the code I’ve done. Its pretty small, but I noticed the garbageCollectStates in pstats building up and impacting on framerate.

This is from opening and closing and unloading 100 documents several times. (A very basic document, I’d imagine this might build up over a full playthrough of a game)

Is this a libRocket thing - or am I just not cleaning up correctly?

[Edit #1]

setting “state-cache 0” seems to eliminate the problem in the below snippet with garbageCollectStates, but doing that completely freezes my game on opening…

[Edit #2]

Which seems to be because I’m implementing a non-standard tag, which normally rocket doesn’t complain about. So thats sorted :slight_smile:

[Edit #3]

Well, “state-cache 0” seems to drop my frame rate from 180 to 40, because of one flattened alpha transparent node, so not sure what the solution is :neutral_face:

Press F2 to remove and reopen the documents:


from pandac.PandaModules import loadPrcFileData

# This kills the panda
#loadPrcFileData('', 'threading-model /Draw')
loadPrcFileData('', 'show-frame-rate-meter 1')
loadPrcFileData('', 'sync-video 0')

from panda3d.rocket import *
from direct.directbase import DirectStart
from pandac.PandaModules import *


class test():

  def __init__(self):

    self.r = RocketRegion.make('pandaRocket', base.win)
    self.r.setActive(1)

    print "RocketRegion created."

    self.ih = RocketInputHandler()
    base.mouseWatcher.attachNewNode(self.ih)
    self.r.setInputHandler(self.ih)

    print "RocketInputHandler created."
    LoadFontFace("assets/Delicious-Roman.otf")   

    self.init()

  def cleanup(self):
    del(self.context)
    base.win.removeDisplayRegion(self.r)
    del(self.r)
    print('Cleaned!')

  def rebuild(self):
    '''
      Close all the open documents and reinitialise them
    '''
    for doc in self.docs:
      doc.Close()
      self.context.UnloadDocument(doc)

    #This doesn't seem to change things
    #self.context.UnloadAllDocuments()

    self.docs = None

    # Make sure things are closed
    print(self.context.documents)

    self.init()

  def init(self):    

    self.docs = []

    self.context = self.r.getContext()

    print "Got rocket context."   

    for x in xrange(0,100):     

      self.docs.append(self.context.LoadDocument('data/main_menu.rml'))
      self.docs[x].Show()

    print "Document loaded." + str(len(self.docs))  


PStatClient.connect()
test = test()

base.accept('f1-up', test.cleanup)
base.accept('f2-up', test.rebuild)

run()

RML:

<rml>
	<head>
		<title>Main Menu</title>
		<style>
			body
			{
				font-family: Delicious;
				font-weight: normal;
				font-style: normal;
				font-size: 150px;
			}

			div
			{
				display: block;
			}

			p
			{
				display: block;
			}

		</style>

	</head>
	<body>
		<p>Test</p>
	</body>
</rml>