Panda3D seems to ignore sortOrder at GUI

Hi community,

I’ve came across an annoying phenomenon that I failed to explain.
GUI widgets are seemingly drawn at random order. Each run produces different result.
I’ve created this simplified code that produces the phenomenon.
Sometimes it yields:


, but sometimes red is at top, sometimes green is, sometimes green is not even visible.

from direct.showbase.ShowBase import ShowBase
from direct.gui.DirectGui import *
class TGame(ShowBase):
	def __init__(self):
		ShowBase.__init__(self)
		T1 = DirectFrame(frameColor=(1, 0, 0, 1), parent=render2d, frameSize=(-0.25,0.25,-0.25,0.25), pos=(0.5,0,0.05), sortOrder = 61)
		T2 = DirectFrame(frameColor=(0, 1, 0, 1), parent=render2d, frameSize=(-0.25,0.25,-0.25,0.25), pos=(0.55,0,0.05), sortOrder = 72)
		T3 = DirectFrame(frameColor=(0, 0, 1, 1), parent=render2d, frameSize=(-0.25,0.25,-0.25,0.25), pos=(0.6,0,0.05), sortOrder = 83)

		self.updateTask = taskMgr.add(self.update, "update")
	def update(self, task):
		pass
game = TGame()
game.run()

I’ve tried adding:
base.render2d.setDepthTest(False)
base.render2d.setDepthWrite(False)
or with True, but it doesn’t seem to affect the result.
I’ve tried to parent them to each other, but also doesn’t seem to work.
What am I doing wrong?

If anything, disabling depth -testing and -writing would be likely to make things worse.

(And if I recall correctly, they’re already disabled for render2d, so those lines shouldn’t have any significant effect here.)

However, it’s odd that you’re seeing inconsistent results–DirectGUI should render in (more or less) order created–in this case, red, green, then blue.

And indeed, when I try your code on my system, that is in fact what I see: across multiple runs, the order of the GUI-objects remains stable and in the above-stated order.

What system are you running this on? (And what version of Panda are you using?)

Perhaps there’s some weird graphics-driver glitch that’s causing this issue, or some platform-specific regression/bug…

Thanks for looking into the problem. It is truly puzzling me, because documentation clear about how it should work.
Originally, I’ve been using Panda3d 1.10.14, but after finding the issue, I’ve updated to 1.10.16.
I’m running a win11 machine (Ryzen 9600, RTX 3060 Ti). I’ve just updated the graphics driver, but didn’t help.
I’ve even built it to exe, but it produces the same result.

I can confirm that I have the same problem; I’m using Windows 10 and a Radeon RX 580. It’s noteworthy that this problem doesn’t occur if the frames are parented to an aspect2d node.

1 Like

Well, indeed. Thanks.
It isn’t supposed to work, but it does. Aspect2d doesn’t exhibit this behavior.

1 Like