Dt between frames is not stable

Hi, I am using Panda3D-1.10.4.1-x64 on Windows 10 and I find it strange of Dt.
I just use globalClock to get Dt, it is about 0.0166(60fps) generally but when the frame count reaches a certain number, next Dt would be 0.33 and then 0.00.
It seems Dt accumulate in that count number.
My code is like this:

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase

class a(ShowBase):
    def __init__(self):
        super().__init__()
        self.clock = ClockObject().getGlobalClock()
        self.taskMgr.add(self.t, 'test')
        self.accept('escape', exit)

    def t(self, task):
        print('frame:', self.clock.getFrameCount(), ' dt', self.clock.getDt())
        return task.cont

a().run()

And it get:
…
frame: 55 dt 0.016560396668392485
frame: 56 dt 0.03314417793298219
frame: 57 dt 0.0006871789233406922
frame: 58 dt 0.01618665338530967
…
frame: 116 dt 0.016262550758932903
frame: 117 dt 0.03332387009323501
frame: 118 dt 0.0006281020487364231
frame: 119 dt 0.01613085855929519
…
My character can not walk steadly because of this.
So I wonder how it could be solved.
Thank you.

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        self.taskMgr.add(self.time, 'time')
        self.accept('escape', exit)

    def time(self, task):
        print('frame:', globalClock.getFrameCount(), 'dt', globalClock.getDt())
        return task.cont

app = MyApp()
app.run()
frame: 985 dt 0.00406893423958854
frame: 986 dt 0.0011907723039419338
frame: 987 dt 0.0025854819641302207
frame: 988 dt 0.0013230329324698253
frame: 989 dt 0.0027587007227829474
frame: 990 dt 0.0010738709742104113
frame: 991 dt 0.0024510880996579942
frame: 992 dt 0.004429877761313872
frame: 993 dt 0.0010213933699878552
frame: 994 dt 0.0026469191593174735
frame: 995 dt 0.0011971720117736062
frame: 996 dt 0.0025581765440469972
frame: 997 dt 0.0012965808067644247
frame: 998 dt 0.003156335902744889
frame: 999 dt 0.0013503383525530488
frame: 1000 dt 0.003963979031143872
frame: 1001 dt 0.0013477784694204686
frame: 1002 dt 0.002507832175768332
frame: 1003 dt 0.0012530627935065652
frame: 1004 dt 0.002661425163736464
frame: 1005 dt 0.001258609206960859
frame: 1006 dt 0.0025223381801877665
frame: 1007 dt 0.004270738359891446
frame: 1008 dt 0.0010952033336502076
frame: 1009 dt 0.002640519451485357
frame: 1010 dt 0.0012266106678011646
frame: 1011 dt 0.002509112117334844
frame: 1012 dt 0.0013789237142027844
frame: 1013 dt 0.003111111300731828
frame: 1014 dt 0.001356311413196476
frame: 1015 dt 0.004153410382971234
frame: 1016 dt 0.0010964832752167197
frame: 1017 dt 0.002626866741443745
frame: 1018 dt 0.0012180777240251572
frame: 1019 dt 0.0025283112408307495
frame: 1020 dt 0.0014126288421176803
frame: 1021 dt 0.002484793227573334
frame: 1022 dt 0.004270738359891446
frame: 1023 dt 0.0012991406898970048
frame: 1024 dt 0.0024502348052806155
frame: 1025 dt 0.0012342903171993491
frame: 1026 dt 0.0025142318836004485
frame: 1027 dt 0.0013008472786522063
frame: 1028 dt 0.0032096668013448237
frame: 1029 dt 0.0014834522754587631
frame: 1030 dt 0.004042482113883139
frame: 1031 dt 0.001285487979855393
frame: 1032 dt 0.002408850027966647
frame: 1033 dt 0.0012159444880812664
frame: 1034 dt 0.002536844184606757
frame: 1035 dt 0.0013418054087770415
frame: 1036 dt 0.0031094047119770707
frame: 1037 dt 0.0013819102445240539
frame: 1038 dt 0.003996830864681833
frame: 1039 dt 0.0013243128740358934
frame: 1040 dt 0.0025244714161316573
frame: 1041 dt 0.001121228812167363
frame: 1042 dt 0.0029950632653785725
frame: 1043 dt 0.0008861462111382501
frame: 1044 dt 0.0025176450611108514
frame: 1045 dt 0.004414518462517059
frame: 1046 dt 0.0010346194328407776
frame: 1047 dt 0.00258846849445149
frame: 1048 dt 0.001183945948921128
frame: 1049 dt 0.0025692693709555847
frame: 1050 dt 0.001517157403374103
frame: 1051 dt 0.00277448666876845
frame: 1052 dt 0.0014651064463406804
frame: 1053 dt 0.004295483896841645
frame: 1054 dt 0.0010657646776230933
frame: 1055 dt 0.0026507589840165657
frame: 1056 dt 0.0012180777240251572
frame: 1057 dt 0.0027505944261956294
frame: 1058 dt 0.0015551290031772247
frame: 1059 dt 0.0020952643441987107
frame: 1060 dt 0.0041862622165087515
frame: 1061 dt 0.0011847992432985066
frame: 1062 dt 0.002692997055707913
frame: 1063 dt 0.0011732797692007857
frame: 1064 dt 0.002584628669752398
frame: 1065 dt 0.0013358323481340584
frame: 1066 dt 0.003117937655752634
frame: 1067 dt 0.001576461362617465
frame: 1068 dt 0.0038265986363503757
frame: 1069 dt 0.001241116672220155
frame: 1070 dt 0.0026166272089125364
frame: 1071 dt 0.001320473049336801
frame: 1072 dt 0.0026063876763813276
frame: 1073 dt 0.0012543427350730774
frame: 1074 dt 0.002694276997273981
frame: 1075 dt 0.004165356504258089
frame: 1076 dt 0.0011766929467111886
frame: 1077 dt 0.0025236181217538345
frame: 1078 dt 0.0015457427650238387
frame: 1079 dt 0.0026119340898356214
frame: 1080 dt 0.0014365210846909449
frame: 1081 dt 0.003140123309570253
frame: 1082 dt 0.001960870479726484
frame: 1083 dt 0.0034020846834939
frame: 1084 dt 0.0011126958683913557
frame: 1085 dt 0.0028380570998995935
frame: 1086 dt 0.001070031149511319
frame: 1087 dt 0.002985250380036053
frame: 1088 dt 0.0013592979435177455
frame: 1089 dt 0.0018328763230863743
frame: 1090 dt 0.004513500610318744
frame: 1091 dt 0.0012449564969196913
frame: 1092 dt 0.002519778297054742
frame: 1093 dt 0.0012338636700106598
frame: 1094 dt 0.002923813184848356
frame: 1095 dt 0.0009083318649563132
frame: 1096 dt 0.002794539086642178
frame: 1097 dt 0.0019647103044255765
frame: 1098 dt 0.004087706715895756
frame: 1099 dt 0.0010580850282249088
frame: 1100 dt 0.002574389137221189
frame: 1101 dt 0.0013328458178123448
frame: 1102 dt 0.0029754374946935336
frame: 1103 dt 0.0011668800613691133
frame: 1104 dt 0.0024003170841906396
frame: 1105 dt 0.004093253129350494
frame: 1106 dt 0.0015103310483532972
frame: 1107 dt 0.0022979217588785517
frame: 1108 dt 0.0011656001198026011
frame: 1109 dt 0.002645212570561828
frame: 1110 dt 0.0012778083304572085
frame: 1111 dt 0.012807521960597423
frame: 1112 dt 0.0006220516012707122
frame: 1113 dt 0.0004065947709270823
frame: 1114 dt 0.003773267737749997
frame: 1115 dt 0.0010563784394697073
frame: 1116 dt 0.004679039719573286
frame: 1117 dt 0.0011532273513275015
frame: 1118 dt 0.0027399282464757313
frame: 1119 dt 0.0012940209236314004
frame: 1120 dt 0.002490339641027628
frame: 1121 dt 0.0013042604561626092
frame: 1122 dt 0.0030705798177961263
frame: 1123 dt 0.0017270678202634393
frame: 1124 dt 0.0042246604635010065
frame: 1125 dt 0.0014732127429275543
frame: 1126 dt 0.0020406535040322638
frame: 1127 dt 0.0010836838595529308
frame: 1128 dt 0.0025820687866193737
frame: 1129 dt 0.0014126288421181243
frame: 1130 dt 0.0031128178894874736
frame: 1131 dt 0.0013371122897001264
frame: 1132 dt 0.004045468644204853
frame: 1133 dt 0.004398732516531556
frame: 1134 dt 0.002570549312522097
frame: 1135 dt 0.0013511916469304275
frame: 1136 dt 0.003018955507951393
frame: 1137 dt 0.0017547998875357962
frame: 1138 dt 0.003696471243765931
frame: 1139 dt 0.0013413787615883521
frame: 1140 dt 0.0025095387645235334
frame: 1141 dt 0.0012219175487242495
frame: 1142 dt 0.00277192678563587
frame: 1143 dt 0.001330712581868454
frame: 1144 dt 0.0023128544104862314
frame: 1145 dt 0.005550253279103856
frame: 1146 dt 0.0013998294264538913
frame: 1147 dt 0.0011766929467111886
frame: 1148 dt 0.0008601207326215388
frame: 1149 dt 0.0026959835860296266
frame: 1150 dt 0.0013345524065671022
frame: 1151 dt 0.0031021517097675755
frame: 1152 dt 0.0016622174475662277
frame: 1153 dt 0.0037054308347306275
frame: 1154 dt 0.001344791939098755
frame: 1155 dt 0.0025573232496691745
frame: 1156 dt 0.0012355702587658612
frame: 1157 dt 0.0027224357117350273
frame: 1158 dt 0.0011331749334537733
frame: 1159 dt 0.002664838341246867
frame: 1160 dt 0.004089839951840091
frame: 1161 dt 0.0014514537362986246
frame: 1162 dt 0.0024818066972516206
frame: 1163 dt 0.001078137446098637
frame: 1164 dt 0.0025867619056962887
frame: 1165 dt 0.0014062291342860078
frame: 1166 dt 0.003017675566384881
frame: 1167 dt 0.0014352411431244327
frame: 1168 dt 0.003970378738975544
frame: 1169 dt 0.0011161090459017586
frame: 1170 dt 0.0026563053974708595
frame: 1171 dt 0.0013810569501471193
frame: 1172 dt 0.002549643600270546
frame: 1173 dt 0.0012953008651979125
frame: 1174 dt 0.0029263730679813804
frame: 1175 dt 0.001790638251395027
frame: 1176 dt 0.0035983423903420686
frame: 1177 dt 0.00127951491921241
frame: 1178 dt 0.0027181692398468016
frame: 1179 dt 0.0011318949918872612
frame: 1180 dt 0.0030756995840617307
frame: 1181 dt 0.0007790577667496912
frame: 1182 dt 0.002438288683993761
frame: 1183 dt 0.004260498827360237
frame: 1184 dt 0.0014232950218380225
frame: 1185 dt 0.0023580790124992923
frame: 1186 dt 0.0013119401055612379
frame: 1187 dt 0.002569696018144274
frame: 1188 dt 0.001271408622625092
frame: 1189 dt 0.0029545317824424266
frame: 1190 dt 0.0014467606172217096
frame: 1191 dt 0.004154263677349057
frame: 1192 dt 0.0012180777240251572
frame: 1193 dt 0.002539404067739337
frame: 1194 dt 0.001198025306151429
frame: 1195 dt 0.00259529484947274
frame: 1196 dt 0.0013102335168055923
frame: 1197 dt 0.002460047690622691
frame: 1198 dt 0.004256232355472456
frame: 1199 dt 0.0011792528298442129
frame: 1200 dt 0.0026631317524916653
frame: 1201 dt 0.0012317304340663249
frame: 1202 dt 0.0027356617745879497
frame: 1203 dt 0.001249222968807473
frame: 1204 dt 0.0030739929953065293
frame: 1205 dt 0.0016131530208540745
frame: 1206 dt 0.003789906978113322
frame: 1207 dt 0.001262022384471262
frame: 1208 dt 0.002605534382003949
frame: 1209 dt 0.0011459743491175622
frame: 1210 dt 0.0027821663181670786
frame: 1211 dt 0.0011169623402791373
frame: 1212 dt 0.0027936857922647995
frame: 1213 dt 0.0039580059705004444
frame: 1214 dt 0.0014032426039647383
frame: 1215 dt 0.0023324801811712703
frame: 1216 dt 0.001284208038288881
frame: 1217 dt 0.0024852198747620236
frame: 1218 dt 0.001426281552159736
frame: 1219 dt 0.0028926679400660404
frame: 1220 dt 0.0017142684046000944
frame: 1221 dt 0.0037728410905613075
frame: 1222 dt 0.0012163711352695117
frame: 1223 dt 0.0026503323368278764
frame: 1224 dt 0.0012078381914939484
frame: 1225 dt 0.002619613739233806
frame: 1226 dt 0.0012441032025418686
frame: 1227 dt 0.0030577804021318933
frame: 1228 dt 0.0013490584109869808
frame: 1229 dt 0.004158530149236839
frame: 1230 dt 0.001305113750540432
frame: 1231 dt 0.0023721583697295934
frame: 1232 dt 0.0014173219611950394
frame: 1233 dt 0.0025739624900320557
frame: 1234 dt 0.0011067228077483726
frame: 1235 dt 0.002694276997273981
frame: 1236 dt 0.004232340112899635
frame: 1237 dt 0.0010320595497077534
frame: 1238 dt 0.002661425163736464
frame: 1239 dt 0.0012325837284441477
frame: 1240 dt 0.002846590043676045
frame: 1241 dt 0.0011190955762234722
frame: 1242 dt 0.002989943499112524
frame: 1243 dt 0.0013601512378955682
frame: 1244 dt 0.004182422391809659
frame: 1245 dt 0.0012590358541499924
frame: 1246 dt 0.0024583411018674894
frame: 1247 dt 0.0013068203392956335
frame: 1248 dt 0.00264649251212834
frame: 1249 dt 0.0012342903171993491
frame: 1250 dt 0.002583348728185886
frame: 1251 dt 0.004112878900035533
frame: 1252 dt 0.0011890657151862882
frame: 1253 dt 0.0026187604448568713
frame: 1254 dt 0.0012185043712134025
frame: 1255 dt 0.002610227501080864
frame: 1256 dt 0.001277381683268075
frame: 1257 dt 0.002994636618189439
frame: 1258 dt 0.0015585421806876276
frame: 1259 dt 0.003916621193187364
frame: 1260 dt 0.0013571647075738547
frame: 1261 dt 0.0023695984865970132
frame: 1262 dt 0.0013187664605820437
frame: 1263 dt 0.0025607364271795774
frame: 1264 dt 0.0013772171254471388
frame: 1265 dt 0.0027715001384471805
frame: 1266 dt 0.0017390139415502937
frame: 1267 dt 0.004159810090803351
frame: 1268 dt 0.0012487963216183395
frame: 1269 dt 0.002501859115125349
frame: 1270 dt 0.0011903456567528004
frame: 1271 dt 0.002780459729411877
frame: 1272 dt 0.0011109892796361542
frame: 1273 dt 0.002713049473581197
frame: 1274 dt 0.004094533070917006
frame: 1275 dt 0.0011557872344600817
frame: 1276 dt 0.0026460658649396507
frame: 1277 dt 0.0012210642543468708
frame: 1278 dt 0.0025074055285796426
frame: 1279 dt 0.0012897544517431747
frame: 1280 dt 0.0029238131848488003
frame: 1281 dt 0.0014002560736425806

This is working properly. Perhaps the problem is in the link that you received during initialization, try adding the task functions inside.

I’m wondering whether it might not be related to the game being V-Synced. Perhaps the game itself completes an update in much less than the 0.0166s required from 60fps–but every so often something causes a momentary slowdown. This results in an unusually-long update, one that ends up finishing just before the next screen-refresh. But because the game’s updates complete quickly, that’s enough time for an update to finish, and thus the long update is followed by a very short update, before a return to the usual 0.0166s-updates.

However, this is all very speculative on my part.

In fact, there is nothing strange in Dt, it depends on the render time of the frame. And accordingly, it cannot be stable.

Of course–but the degree of stability shown in the original poster’s output indicates that V-Sync is likely on, and with the simplicity of the test-program and the reliability of the spikes in frame-time, this specific issue does seem rather odd.

[edit] In fact, note that the “spike” has a frame-time that corresponds to 30fps, if I’m not much mistaken. I’m thus more confident that what I described above seems likely to be what’s happening.

I found it is because I enabled framebuffer-hardware in config file. When it is disabled I get the same result as yours.
So it is due to my GPU?
I am using NVIDIA GeForce GTX 1050.
But when I enable framebuffer-software, the program would report errors like this:

:display:gsg:glgsg(error): at 7890 of c:\buildslave\sdk-windows-amd64\build\panda\src\glstuff\glGraphicsStateGuardian_src.cxx : invalid enumerant
:display(error): Deactivating wglGraphicsStateGuardian.

Does it matter? The program continue to run even though errors raised continuously.

I don’t understand why you turn it on? What a necessity this is caused…

I have GeForce GTX 1050, too, and I can confirm that I also have those “hiccups”. One frame takes too long, then the next frame tries to catch up, and it’s too short. They are noticeable every second or so. This looks rather unpleasant.

I disable framebuffer-hardware and enable framebuffer-software, there are problems with the image, and I also have the following error:

:display:gsg:glgsg(error): GL error 0x500 : invalid enumerant
:display:gsg:glgsg(error): An OpenGL error has occurred.  Set gl-check-errors #t in your PRC file to display more information.

And if I enable gl-check-errors, then:

:display:gsg:glgsg(error): at 7890 of E:\Projects\Dev\panda-source\panda\src\glstuff\glGraphicsStateGuardian_src.cxx : invalid enumerant

If you mean the “framebuffer-hardware” setting, I think that it’s on by default. It I’m not much mistaken, it instructs Panda to use hardware acceleration, rather than software.

I meant this line. I meant this line. It makes no sense to include. framebuffer-software

OK, this seems to be unrelated to the video card. The stuttering appears only when there are many background tasks running. If I close Google Chrome, Visual Studio, PyCharm and some other programs, my Panda3D program gives me steady framerate.

1 Like

Ah, I see–my mistake, then!

It makes some sense for testing purposes, I think, or in the case that the program is extremely undemanding and the “software” setting gives better results.

It looks like overheating of the processor.

The temperature is good, but it definetely caused by some resource shortage. I am not an engineer, so can’t really tell. Anyway, it’s unrelated to Panda3D or the specific graphics card.

It could be as simple as one of those applications periodically engaging in some relatively-expensive task, I imagine.

I’m not sure if this is related, but when I’m using the discrete NVIDIA card on my laptop, a simple Panda application (that does nothing intensive) will run with very inconsistent framerate. As I started adding things to the application, the framerate stability markedly improved, however.

I noticed this when I put a print statement in a task that just printed something every frame; my minimal game ran very stably with the print statement added, but it was unstable without the print statement. Though, since you do see the issue with such a print statement, it may not be the same issue.

If this is the same issue, this may be worth investigating. It might have something to do with either the CPU or GPU getting frames done too fast for the other one to be able to keep up with, or something like that.

@Thaumaturge’s guess about V-Sync is not a bad one; have you tried turning off V-Sync in the driver settings and in Panda config?

I closed all applications and restarted and got the same result.
I think it’s related to video card. When I use my integrated graphic(Intel(R) HD Graphics 630
) to run the game, the dt is very steady of about 0.0166(although it fails to load some textures).
I also test the same program on other cards: GeForce GTX 1050 Ti has the same problem while AMD R5 M330 and graphics have steady dt of 0.0166.

I don’t have integrated graphics on the current PC, but I’ve tried with an old GeForce 740 and got the same results (stutterring when running with Visual Studio debugger).

Does your app have many models/shaders? Note that rdb said that a more GPU-heavy Panda3D app runs steadily for him. You can try running a more complex Panda3D program to test this. I would recommend this game A Door to the Mists--Demo released! by Thaumaturge.

Also, did you try disabling Nvidia overlay?

I did that but it had no effect.

Thank you for trying. Seems that it existed in this card series.
Following rdb I added bunch of models with complicate shader and found that it indeed avoid this problem as long as more than 0.0166s is required to render a frame.
However, when it is not heavy enough it still happen.
By the way, where is Nvidia overlay, I can’t find it anywhere.