Sound stutter while loading a collection factory (SOLVED)

I implemented background music today and I noticed that the sound stutters for a frame or two when I’m loading a collection factory (calling create).

The music is an ogg file if that makes any difference.

1 Like

See this thread: Sound stops while loading collection proxy (SOLVED)

Thanks. Too bad it’s not solved yet, but I’ll try to change to a collection proxy instead of a factory and see if that improves things.

Is there an issue number assigned to this?

I tried using a collection proxy with async_load, but that didn’t really help. I’ll probably go with @Adam_Westman’s Debeat library and fade out the sounds before loading the new collection (since there is a loading screen in-between in my case).

2 Likes

Well, the uploading of textures is asynchronous now (1.2.107) so it should be something else that is causing the stuttering.
What else is in the collection? How large is it?

1 Like

There are two large background sprites and 25 game objects, some are referenced from a go file and some are regular game objects, using 2 texture atlas in total if I’m not mistaken. I can see if I can find a minimal repro case if you guys can’t reproduce it.

2 Likes

I tried to narrow down the cause and I think it has to do with gui (textures?). I’ve attached as small a project as I can. Just start it and press the mouse button to load the second collection and observe the stuttering sound. At least on my machine :wink:

sound_stutter.zip (903.2 KB)

Also, I found a work-around in my own project and that is to disable dynamic loading on the collection factory.

Hi Gregor,

This is expected behaviour.

When factory dynamic loading is disabled, the resources contained (in the collection or go) are loaded with the parent collection.

When factory dynamic loading is enabled, you’re expected to call factory.load/unload as needed meaning you control when the resources are loaded and unloaded in memory. Load/unload are asynchronous calls.

If you call factory.create on a factory with dynamic loading enabled without having called load (not having the resources in memory) it will create the resources needed in the create call synchronously which is why you get the stutter.

If you want to go with dynamic loading, you should load like this in your init function:

self.loaded = false
collectionfactory.load("#loaded_factory", function(self, url, result) self.loaded = true end)

Then check the self.loaded flag before creating the factory. That will remove the stuttering since the factory now has been asynchronously loaded.

Note that all this applies to both collectionfactories and factories.

For more information, check the documentation here:


5 Likes

I didn’t realize that I should use load instead of create! Thanks, I’ll try it out!

5 Likes