If you use AnimateMD2 with a speed bigger than the difference between the first and last frame, the program will eventually crash at RenderWorld (displaying the message "Memory Access Violation" even in debug mode)
This happens in loop (1) and pingpong (2) mode. I couldn't reproduce it in play-once (3) mode for any speed.
Usually this isn't too big a problem because the speeds just are not that high.
But I want to adjust the animation speed to the mean framerate at least at the beginning of the animation.
To do this, I calculate the mean framerate of the last x seconds. When I start an animation, I multiply the mean framerate with an FPS independent speed constant (i.e. animation frames per second instead of animation frames per rendered frame)
If now the frame rate drops for some reason, and at the same time an animation is started (with a big calculated speed now), and some time later, a MAV will happen at RenderWorld, if the animation hasn't been stopped until that.
I'll provide a modified version of the dragon example from the b3d demos.
Note the lines
Here it starts:
Crash times:
This happens in loop (1) and pingpong (2) mode. I couldn't reproduce it in play-once (3) mode for any speed.
Usually this isn't too big a problem because the speeds just are not that high.
But I want to adjust the animation speed to the mean framerate at least at the beginning of the animation.
To do this, I calculate the mean framerate of the last x seconds. When I start an animation, I multiply the mean framerate with an FPS independent speed constant (i.e. animation frames per second instead of animation frames per rendered frame)
If now the frame rate drops for some reason, and at the same time an animation is started (with a big calculated speed now), and some time later, a MAV will happen at RenderWorld, if the animation hasn't been stopped until that.
I'll provide a modified version of the dragon example from the b3d demos.
Note the lines
; !! HERE: Use animation speed bigger than (end - start) ;speed#=65 ; will crash at frame no. 2 speed#=1.5 ; will crash at frame no. 319 AnimateMD2 dragon, 1, speed#, 39, 40
Here it starts:
;0,40 : idle ;40,46 : run ;46,54 : attack ;54,58 : paina ;58,62 : painb ;62,66 : painc ;66,72 : jump ;72,84 : flip Global info1$="Dragon Demo" Global info2$="Use arrows keys to pan, A/Z to zoom" Global info3$="MD2 Dragon model courtesy of Polycount" Include "../start.bb" ;environment cube cube=CreateCube() FitMesh cube,-250,0,-250,500,500,500 FlipMesh cube tex=LoadTexture( "chorme-2.bmp" ) ScaleTexture tex,1.0/3,1.0/3 EntityTexture cube,tex EntityAlpha cube,.4 EntityFX cube,1 ;floor mirror m=CreateMirror() ;simple light light=CreateLight() TurnEntity light,45,45,0 ;camera camera=CreateCamera() cam_xr#=30:cam_yr#=0:cam_zr#=0:cam_z#=-100 ;cool dragon model! tex=LoadTexture( "model\dragon.bmp" ) dragon=LoadMD2( "model\dragon.md2" ) EntityTexture dragon,tex PositionEntity dragon,0,25,0 TurnEntity dragon,0,150,0 ; !! HERE: Use animation speed bigger than (end - start) ;speed#=65 ; will crash at frame no. 2 speed#=1.5 ; will crash at frame no. 319 AnimateMD2 dragon, 1, speed#, 39, 40 While Not KeyHit(1) played#=played#+speed# frames=frames+1 If KeyDown(203) cam_yr=cam_yr-2 Else If KeyDown(205) cam_yr=cam_yr+2 EndIf If KeyDown(200) cam_xr=cam_xr+2 If cam_xr>90 cam_xr=90 Else If KeyDown(208) cam_xr=cam_xr-2 If cam_xr<5 cam_xr=5 EndIf If KeyDown(26) cam_zr=cam_zr+2 Else If KeyDown(27) cam_zr=cam_zr-2 EndIf If KeyDown(30) cam_z=cam_z+1:If cam_z>-10 cam_z=-10 Else If KeyDown(44) cam_z=cam_z-1:If cam_z<-180 cam_z=-180 EndIf PositionEntity camera,0,0,0 RotateEntity camera,cam_xr,cam_yr,cam_zr MoveEntity camera,0,0,cam_z UpdateWorld RenderWorld Text 10, 10, "Frames rendered: " + frames Text 10, 20, "Animation frames played: " + played# Flip Wend End
Crash times:
speed frames frames*speed 129 1 129 65 2 130 33 4 132 17 9 153 9 19 171 5 39 195 3 79 237 2 159 318 1.5 319 478.5 1.25 639 798.75 1.125 1279 1438.88 1.0625 2559 2718.94 161 [will crash before first frame]