Time Not Updating

Could anyone explain why time does not update when running inside Panda? It seems to only update every 60 seconds or so, but it’s not very consistent.

Here, I’m trying to update time every second using a task. If you uncomment the print statement below you will see that it’s the variable not updating rather than Panda not redrawing it correctly. Does Panda mess with the system time?

from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task
import datetime

class World(DirectObject):
    def __init__(self):

        #Show time
        self.TimeText = OnscreenText(scale=0.08, pos=(0,0), align=TextNode.ACenter, shadow=(0,0,0,1), fg=(255,255,255,1), mayChange=True)
        self.timeTask = taskMgr.doMethodLater(1, self.getTime, 'timetask')

    def getTime(self, task):
        now = datetime.datetime.now()
        #print now.strftime("%a, %b %d %I:%M:%S %p")
        self.TimeText.setText(now.strftime("%a, %b %d %I:%M:%S %p"))
        return task.again

w = World()

Panda doesn’t, but DirectX does. It’s really annoying, but opening a DirectX window seems to force the FPU into single-precision mode. There’s an option on DirectX not to do this, and we’re setting that option, but it doesn’t seem to matter.

This causes problems with the time-of-day, which is returned as a floating-point number of seconds since 1970. This requires a double-precision float. If you’re in single-precision mode, there’s only enough bits to show an update about every 60 seconds or so.

It causes other problems too, but the time-of-day is the most visible and annoying.

One workaround is to use OpenGL instead of DirectX. I haven’t found any reliable workaround while using DirectX. If anyone knows of any, I’d love to hear it.


David, thanks for the information. Hopefully, this is something that can be fixed in future versions - whether it be a Panda workaround or getting the DirectX to behave properly. Thanks again.