“playing offset of the sound on channel” conditions cause CPU usage to cap out

I’m making a rhythm game that essentially functions similarly to simon says. Enemy goes “Left, Right”, and you have to repeat after them on beat.

I’m using the “playing offset of the sound on channel” condition to manually adjust the timing, but the issue is that having just more than around 5 of these conditions causes my CPU to max out when previewing the game, even from the start when nothing is even happening yet. This leads to the preview freezing and giving me a “Gdevelop is not responding” error, which then forces me to close the game or it’ll crash/just freeze forever.
Is this condition supposed to be resource intensive?

Using normal timers doesn’t lag the game at all, but I’ll then face the issue of an audio/input desync if there’s any FPS drops in the game.

This is an image of the same thing but using the offset condition, which then causes the CPU crash.

If anyone has any ideas for fixes or knows why this happens, please let me know.

maybe you can replace it with play a music file
just go to action and see the image:

oh and make sure the looping it turned of but wait… so at beginning at the scene, timer and than play music file. i did not test it

What’s causing the problem? Is it constantly checking the offset or the playing of the sounds?

If it’s the offset then maybe try using a variable to hold the offset value and just check it once per frame. Then compare the variable instead of getting the offset.

Like this?

It’s the checking of the offset that’s causing the lag I’m sure, since the performance drastically changes after disabling the condition.
I tried your solution and it works much better. It doesn’t crash the game anymore, although its CPU usage is still higher than just using timers. I’m a little worried about how the game will run after adding more assets, though.

Here’s the CPU usage when directly using the “playing offset of the sound” condition:

Here’s the one using a normal timer:

And here’s the one where I use variables to hold the offset value instead:

Edit: replied twice by accident

I don’t know if it’s a bug or it’s just not efficient or designed for that.

Have you tried using the profiler? Maybe also test it without all of the play events. I’ve had sounds cause lag. Maybe try different sound files or formats. I don’t know which format or format settings are the best.

Something to mention in your screenshots is that although GDevelop is using more CPU when you are using the conditions, it is only 33%.

What else is taking up the remaining 67%?

(Additionally, GDevelop taking 10% just when playing audio is unusual in itself, and I can’t reproduce that. Is there a chance something is going wild with your audio drivers on your PC?)

Here’s my project if you’d like to take a look. I swapped out some of the audio for generic ones because the original files were personal, but it still performs similarly. The aac audio files might be a bit lighter?

The remaining 67% seemed to be Chrome and Microsoft Defender. It should be noted that they’re both normally very low, but their CPU usage suddenly spiked up as well once I launched the game preview. (The numbers kept jumping around.)

Unfortunately, at this point it seems like something specific to your PC.

This is running your project. not running the preview it gets about 0.2%, running the project it gets about 0.9% after starting the audio, which is what I would expect.
image

Oh yikes…
I have no idea what it could be here but I’ll try tinkering around, I suppose it could also just be getting old.
Thank you very much for checking for me, though! At least now I know it could run fine on other people’s computers if not on mine.

Was this using the timer conditions? Out of curiosity, what was the CPU usage like when checking directly from the offset condition?

That is with the expected events enabled out of the box on your project (offset).

Switching to timer makes it around 1% total.

1 Like

Just a comment about the events. As it stands, you are potentially playing sound multiple times in one game frame on channel 0. If, for example, the sound offset is more than 10.15, then there are 7 times a sound is played on channel 0 (all the conditions that are met are underlined in red) :


Consider adding another condition to each event that creates a range, whether it’s checking the offsets or using a variable, so that only one sound is only played. So, for example, the first one you could add an extra condition that checks that the offset < 6.4.

2 Likes

Got it, thank you guys very much for all the assistance. I’ll mess around with it some more and try to see if I can fix whatever is going on with my PC as well.