Background Loading freezing main thread

Godot Version

4.2.1 Stable

Question

I’m using the “ResourceLoader” to load my scenes, for whatever reason, the main thread freezes during loading. This happens regardless of sub threads being set to true or false. Isn’t this not supposed to happen? I’ve asked quite a few people now about it and no ones been able to figure out why it’s happening.

ResourceLoader.load_threaded_request(scene_path, “PackedScene”, true)

This is the main code to start the load. I made sure that it wasn’t the checking of the threads progressing causing it, as taking out all my code that is in a process function makes no difference. Changing scenes to the loaded one isn’t what is causing it either as I’ve tried taking that out too to see if it made a difference. Been trying to figure this out for days and greatly appreciate any help. I can provide more context and videos if required.

Thanks!

2 Likes

Setting sub thread to true will spawn many threads. Probably at least one per core. Which could effect scheduling of the main thread.

The other half is the getting, you need to make sure you don’t spin lock or block with the get or get status (like using a while loop). And try again in another process call.

Thanks for the suggestions! As i mentioned in the post, having sub threads set to false didn’t make much of a difference with the freezing, so I have to assume its something with the getting status… Will test some things out

How do you get the resource? Since the only function to get the loaded resource will block the main thread if it’s still loading.

1 Like

As a test, i removed all the code that checks the progress and such and just have a spinning cube to see when its being frozen, it still happens to freeze during the loading of scenes, not as much but it is still very noticeable

Okay, that’s interesting.

Are there other resources loading at this time? I assume the background resource is large, and could form a blockage and bottle-neck on the file I/o request effecting other loading resources that are not being loaded in the background?

I’m not very sure. By background resource, are you referring to the loading-screen scene itself or the scene I’m trying to load into?

I guess just the scene your loading into. I was wondering if there were more than one load happing at the time you start the background loading. Like a player or item or something.

I assume there isn’t since the resource loader is just called during the ready function. The scene contains a bunch of stuff of course, but it’s only technically loading the one scene given

1 Like


Here’s a before and after. It used to take a very long time to load the scene but I optimized it a bunch thinking it would fix the freezing. But it doesn’t seem to

Hmm okay, are the video’s true to experience? It almost looks like the video card is freezing, because I can see the Nvidia Experience overlay and it also seems to freeze.

1 Like

Tested it on a few other pcs, one just had integrated graphics and was the same result

The main issue with the freezing is if you click during it, it’ll cause the windows unresponsive box to come up, which makes it really annoying if you do it by accident

1 Like

I’m running out of ideas, that scene does look pretty hefty.

Have you attempted profiling the issue?

If the editor profiler doesn’t give any clue, uou could try a more low level profile.

yes i just get this
image
image

doesn’t give more information than that, scrolling down all other processes are normal


here’s visual profiler. Haven’t tried external profilers like the ones you sent but I will take a look at those next

One last thought, the default load request will try to cache the resource. Maybe setting it to cache_ignore would be more appropriate?

1 Like

doesn’t seem to make a difference, but set it to that just in case

Seems I’ll have to live with the freezing for now. Appreciate the help though! Hopefully it’s just some Godot bug that gets fixed in a later version or something