Random freezeing with uncapped framerate

Hi, I am rather new to Panda and already encountered an issue that is weird to me.
I’m writing simple 3d Tetris where tetrominoes are moved using posInterval() but sometimes a random freeze happened. A falling puzzle would suddenly stop and then after 1/2s appear much lower like the game was running in the back and just the screen wasn’t updated. In addition, the issue stopped when I print ed something every frame or connected the app to pstat. Finally, I fixed it by setting const frame-rate ;D.
My question is what could have been the reason for that random freezing?

Check out the code from the lesson. https://www.panda3d.org/manual/?title=Using_Intervals_to_move_the_Panda If there is no frieze, then the problem is in your code.

1 Like

OH, freezing happens on this example too, but also setting const fps solves the problem.

Actually intervals are unnecessary to move. Surprisingly, the panda offers unpopular textbook solutions. Intervals have a problem, the time that the panda is trying to calculate to move is not constant for each frame. Object properties are also blocked, for example, you cannot control the Z axis. Use task manager for this purpose.

I changed the code:

from math import pi, sin, cos
 
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor
 
class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
 
        # Disable the camera trackball controls.
        self.disableMouse()
 
        # Load the environment model.
        self.scene = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        self.scene.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.scene.setScale(0.25, 0.25, 0.25)
        self.scene.setPos(-8, 42, 0)
 
        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        
        # Load and transform the panda actor.
        self.pandaActor = Actor("models/panda-model", {"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.setPos(0, 10, 0)
        self.pandaActor.reparentTo(self.render)
        # Loop its animation.
        self.pandaActor.loop("walk")
        
        # Run 1 interval
        self.taskMgr.add(self.pandaPosInterval1, "pandaPosInterval1")

        #Moving speed
        self.speed = 1
        #Rotational speed
        self.rotational = 50

    def pandaPosInterval1(self, task):
        if self.pandaActor.getY() <= -10:
            self.pandaActor.setY(-10)# Stop the increase in error over time.
            self.taskMgr.add(self.pandaRotation1, "pandaRotation1")
            return Task.done
        else:
            self.pandaActor.setY(self.pandaActor.getY()-self.speed*globalClock.getDt())
        return Task.cont

    def pandaRotation1(self, task):
        if self.pandaActor.getH() >= 180:
            self.pandaActor.setH(180)# Stop the increase in error over time.
            self.taskMgr.add(self.pandaPosInterval2, "pandaPosInterval2")
            return Task.done
        else:
            self.pandaActor.setH(self.pandaActor.getH()+self.rotational*globalClock.getDt())
        return Task.cont
        
    def pandaPosInterval2(self, task):
        if self.pandaActor.getY() >= 10:
            self.pandaActor.setY(10) # Stop the increase in error over time.
            self.taskMgr.add(self.pandaRotation2, "pandaRotation2")
            return Task.done
        else:
            self.pandaActor.setY(self.pandaActor.getY()+self.speed*globalClock.getDt())
        return Task.cont
        
    def pandaRotation2(self, task):
        if self.pandaActor.getH() <= 0:
            self.pandaActor.setH(0)# Stop the increase in error over time.
            self.taskMgr.add(self.pandaPosInterval1, "pandaPosInterval1")
            return Task.done
        else:
            self.pandaActor.setH(self.pandaActor.getH()-self.rotational*globalClock.getDt())
        return Task.cont

    # Define a procedure to move the camera.
    def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont
 
app = MyApp()
app.run()

Hi @mblasiak, it would be great if you could run PStats and add want-pstats true in Config.prc. This will pop up the Panda performance dialog. I wonder if your chugs will show up in PStats, and if so, in which categories. You’ll be able to click the coloured labels in order to zoom in further on a particular category.

It would also be great to know more about your system. Are you using Panda3D 1.10? Are you on Windows, Linux, or macOS?

1 Like

I can add that the intervals have an unknown problem. When I used a laptop and had lessons on C ++,
all examples worked for me, except for intervals. The program, when I tried to launch it, crashed, unfortunately, I don’t remember the details, it was a long time ago.

So:
I’m testing everything on the example of walking panda from tutorial.
Freezes happen on bare tutorial example (program freezes randomly for at least 1/3s then jumps forward like the program would run in the back)
The problem doesn’t show up when I connect example to pstat. As the problem doesn’t appear with pstat, the plots look good to me(nothing exceeds 2ms).
I’m using Linux Mint
Linux 4.15.0-45-generic x86_64)
DISTRIB_DESCRIPTION=Linux Mint 19 Tara
On Huawei MateBook D
NVIDIA GeForce MX150, + Intel UHD Graphics 620
Intel Core i5-8250U
Panda 1.10.0
I attach screen shot just in case:

Using code of serega-kkz freezes still randomly happen.
:worried:

Hmm, then these are not intervals. Maybe this is your IDE, try to run without an IDE, for example via the command line.

1 Like

I don’t think this issue has anything to do with intervals or running from the IDE. That would seem rather odd.

As it happens, I have a laptop with almost identical specs to yours. I’ll give it a try on my end.

1 Like

Running it directly from console doesn’t make difference, I’ve tried it before posting here.
I think the freezing appears only when the interval time is relatively big to the distance and frame rate must be high.
Maybe the moving distance calculated each frame is rounded to zero due to floating point limitations or sth similar, but this way only one object should be effected not whole scene i suppose.

Well, we sort of found out that the intervals are irrelevant. Now the main suspect is a task manager.
Similar problems can cause the same. Overheating of the processor, hard disk operation. I think you need to look at the system resource monitor.

You could try putting a little 1ms sleep in your application:
client-sleep 0.001
But, this will really be equivalent to limiting your framerate.

This is possibly also related: https://www.panda3d.org/manual/?title=FAQ#Why_are_my_animations.2Fintervals_sometimes_skipped_when_I_run_something_heavy_on_the_CPU_before_playing_them.3F