godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.46k stars 21.27k forks source link

[Regression] ResourceLoader.LoadThreadedRequest(scenePath) stuck at 0.5, infinite loop. #99128

Open conde2 opened 2 weeks ago

conde2 commented 2 weeks ago

Tested versions

NOTReproducible in: v4.3 stable for Windows

Reprodcible in: v4.3 stable for MacOs v4.4.dev4.mono.official [36e6207bb] (Windows and MacOS)

For MacOS and Windows

System information

Godot v4.4.dev4.mono - Windows 10.0.19045 - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 32.0.15.6094) - AMD Ryzen 7 3700X 8-Core Processor (16 threads)

Issue description

When using

ResourceLoader.LoadThreadedRequest(scenePath);

This happened before and looks like its still happening: https://github.com/godotengine/godot/issues/92844#issuecomment-2167849384

NOTE: I'm calling the render server when loading TileSets, but I'm doing a RenderingServer.ForceSync();

I'm getting stuck at 0.5 progress and the progress never changes, maybe a recursive load? Or a race condition, I don't know, my debugger points here:

image

Steps to reproduce

I'm loading the instance like this:

In MacOS it doesnt work at all it is always stuck (thats why we did the load in the same thread), on windows there is a race condition, so sometimes it works, sometime it doesnt.

public partial class Main2 : Node2D
{
    public override void _Ready()
    {
        // Construct the path to the scene file
        var scenePath = $"res://main.tscn";

        var error = ResourceLoader.LoadThreadedRequest(scenePath);
        GD.PrintErr($"Loading scene: {scenePath} {error}");
        var percentageReport = new Godot.Collections.Array();

        double percentage;
        ResourceLoader.ThreadLoadStatus loadingStatus;
        do
        {
            loadingStatus = ResourceLoader.LoadThreadedGetStatus(scenePath, percentageReport);
            if (loadingStatus == ResourceLoader.ThreadLoadStatus.Failed)
            {
                GD.PrintErr($"Failed to load scene at path: {scenePath}");
                return;
            }

            percentage = percentageReport[0].As<double>();
            GD.PrintErr($"Loading scene: loading: {loadingStatus} scene: {scenePath} percentage: {percentage} {percentageReport}");
            RenderingServer.ForceSync();
        } while (loadingStatus == ResourceLoader.ThreadLoadStatus.InProgress);

        GD.PrintErr($"Finished loading scene: {scenePath} {loadingStatus} {percentage}");
    }
}

Minimal reproduction project (MRP)

bug-thread.zip

conde2 commented 1 week ago

@RandomShaper I managed to create a MRP:

bug-thread.zip

To reproduce just hit the play project multiple times, at some point it will hang and be stuck in the infinite loop.

https://github.com/user-attachments/assets/a5a14378-2017-413f-b963-88aaffe5099e

conde2 commented 1 week ago

Further investigating I found that removing this script makes the load completes:

Image

Maybe this can help somehow.