Hey all, my game has some video assets that need to swap smoothly, and this is the code I’m using. Basically there are two layers of videoplayers, and the “base” video never stops playing, while video2 pops in and plays when certain events happen. (I’m not a real programmer so self-taught jank code incoming probably):
This works perfectly on all my test machines, but I’ve had some reports of the game hanging and crashing, and the timing of it lines up with the last while loop never progressing forward. Any ideas on why this would be happening on some machines? And how I could avoid it? Thanks!
To me it looks like all of your while() loops are fine: they all yield within the loop body.
So unless one of the properties you access in there contains in itself a loop that doesn’t return, it feels like perhaps something else is locking up.
It is also possible that one of the properties you access in the while() loop’s condition has to access something in a lower-level driver and requires a lock to be acquired, and for some reason the lower-level driver crashed while retaining a lock… hard to say without attaching a debugger.
Also: nothing really jank about the code above: it’s all just nice clean one-thing-at-a-time code, just the way Papa woulda written it. My only comment is that line 25 seems odd that it just arbitrarily waits for 0.04 seconds (a “magic number”), but I doubt that’s a problem…
Hmmmm well, perhaps the clue is in the meaning of “hanging”. It might not be a freeze we’d expect from an infinite loop but merely the video not playing (to end) and thus the game doesn’t continue to the next step.
Particularly this condition:
I wouldn’t trust a video (player) to know the exact number of frames ahead of time. I just don’t. And the cast to (ulong) is curious. This would mean that frameCount may be a ulong and can thus be a much higher value than frame could ever be.
Pretty sure that sort of check is entirely unnecessary anyway because if frame and frameCount match then isPlaying should become false anyway, right?
I would call it bad practice to base your logic on exact frame counts in any case, including the initial frame < 3 check. To what end? If loading the Fmod audio takes a little, check that object for being loaded. If it’s for timing reasons, wait for a given time like 50 ms not number of video frames.
Hey all, thanks for the responses.
I should’ve added this to the initial post, this is from a picture of a screenshot that a player took before the application closed/crashed.
I don’t think I’ve ever seen that style of pop-up error with the loading bar looking thing before, but in the video the game freezes, that pops up, the bar moves for a bit, then the whole thing closes.
Yeah this is all in the service of avoiding the black stutter frames when switching videos that occurs because in my experience VideoPlayer.Prepare() doesn’t really do what it purports to do… if you wait for isPrepared then .Play(), it won’t be seamless (hence waiting for frame 3). I think you’re right that potentially the video doesn’t stop playing, and it gets locked up there somehow. I’m down to try rewriting with no frame references and just some built in ms of delay.
That popup is a runtime crash. You should check the player.log for details, if any.
The colors are odd though. Perhaps that user’s machine has some graphics issues and that’s causing the crash? Can’t hurt to get the player.log because this also contains details about the device like GPU and driver version.
Yeah partially why I’m here if I’ve been unable to walk this player through the process of un-hiding AppData and all that, I’m not sure they even know what file explorer is. Thanks tho!