Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceLoader.load_threaded_request use_sub_threads = true causes Player to crash semi-randomly #84012

Open
cosmoddd opened this issue Oct 26, 2023 · 5 comments

Comments

@cosmoddd
Copy link

cosmoddd commented Oct 26, 2023

Godot version

4.2 Beta 3, 4.2rc2

System information

Godot v4.2.beta3 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2060 (NVIDIA; 31.0.15.3758) - Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz (12 Threads)

Issue description

Note: This issue may be related to #78734. While that issue had resolved for me personally, (first in #78974 and later in #85039), I believe this new issue is being caused by something else. The behavior around this crash is different. It may center around how the ResourceLoader.load_threaded_request uses sub-threads to unpack more complex scenes or scenes that contain other scenes. If you need me to provide more information or more detailed crash dumps, let me know.

When I try to load a specific level in my game, the Player crashes to desktop. This has happened across three different computers, three different versions (4.1.2, 4.2b3, 4.2rc2) and two environments (Windows, Linux).

When I try to attempt to start the game again, there is a chance it may work. The functionality of the level loading successfully is unpredictable but I've noticed several factors:

  • It tends to happen when I've just loaded or reloaded the project, or have made a change to the scene, however significant.
  • It might load successfully after the first or second failure.
  • It only happens on certain levels which are more complex, not others.
  • It might work successfully until I've substantially changed something, reset or reloaded the project.
  • The crash occurs before any of the scripts in the scene enter _init(), so there's no way for me to troubleshoot if it's a specific object or script in the scene. Based on the info I've gleaned, the crash seems to happen as it's doing a threaded request on a file as it's assembling it into a PackedScene for loading.

In the below scene you will see two unsuccessful attempts to load the level, followed by a successful one. The successful load happened when I switched the visibility of two identical nodes.

note: more in-depth tests are below in the comments, but it points to the same problem

loading thread working

Windows error:

Faulting application name: Godot_v4.2-beta3_win64.exe, version: 4.2.0.0, time stamp: 0x00000000
Faulting module name: Godot_v4.2-beta3_win64.exe, version: 4.2.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x00000000002ee662
Faulting process id: 0x0x282C
Faulting application start time: 0x0x1DA08139EF66271
Faulting application path: C:\Users\gregh\AppData\Roaming\Godot\app_userdata\Godot Version Manager\versions\Godot_v4.2-beta3_win64.exe
Faulting module path: C:\Users\gregh\AppData\Roaming\Godot\app_userdata\Godot Version Manager\versions\Godot_v4.2-beta3_win64.exe
Report Id: 90acc9f6-6ec0-4952-889d-b89f59e423a5
Faulting package full name:
Faulting package-relative application ID:

Steps to reproduce

Download the scene here, also posted below.

Press F5 top run the game.

Start a new game and follow the prompts.

Notice that the scene either runs or crashes.

Quit the game manually.

Try this ten times. Try making some minor changes in the scene. Several attempts should reveal that there is no consistency to whether the level to loads or the game to crashes.

Minimal reproduction project

Download the scene here, also posted above.

@cosmoddd
Copy link
Author

#85039 seems to have fixed this.

@akien-mga akien-mga added this to the 4.2 milestone Nov 27, 2023
@cosmoddd cosmoddd reopened this Nov 27, 2023
@cosmoddd
Copy link
Author

cosmoddd commented Nov 27, 2023

Upon further testing, it is still happening. The crashing is still unpredictable, but where it happens is consistent. I've tested it on Linux (Steam Deck) and Windows.

To break down the issue further, I split my largest scene into a series of smaller scenes, in order to pinpoint the problem.

I will provide a more thorough breakdown of where it happens, along with an updated test build, ASAP.

@akien-mga akien-mga modified the milestones: 4.2, 4.x Nov 27, 2023
@cosmoddd
Copy link
Author

The updated project file is here, same as in the above description. The instructions for replicating this bug remain the same as in the above description.

In order to get more specific info from this test, I have set up a series of seven levels, loaded sequentially, via the load_threaded_request command.
image

The first five scenes mostly contain level geometry, textures and collisions. The last two scenes, StationObjects (station_interior_objects.tscn) and StationPeople (station_interior_people.tscn) , are the more complex scenes. StationPeople has seven separate sub-scenes. Each of those subscenes has the same subscene within that. These sub-scenes include mesh data, skeletons, bespoke animations, a variety of different texture files. As far as I can tell, they're not heavy, but they are intricate.

After going through the new game prompt, I go through the loading sequence eleven times.

Test 1 - Crash at StationPeople (station_interior_people.tscn)
Test 2 - Crash at StationPeople (station_interior_people.tscn)
Test 3 - Loads normally
Test 4 - Loads normally
Test 5 - Crash at StationPeople (station_interior_people.tscn)
Test 6 - Crash at StationPeople (station_interior_people.tscn)
Test 7 - Crash at StationPeople (station_interior_people.tscn)
Test 8 - Crash at StationPeople (station_interior_people.tscn)
Test 9 - Crash at StationPeople (station_interior_people.tscn)
Test 10 - Crash at StationObjects (station_interior_objects.tscn)
Test 11 - Crash at StationPeople (station_interior_people.tscn)

loading thread issues 3_resized

I do this again another 10 times.

Test 1 - Crash at StationPeople (station_interior_people.tscn)
Test 2 - Crash at StationObjects (station_interior_objects.tscn)
Test 3 - Crash at StationPeople (station_interior_people.tscn)
Test 4 - Crash at StationPeople (station_interior_people.tscn)
Test 5 - Loads normally
Test 6 - Crash at StationPeople (station_interior_people.tscn)
Test 7 - Crash at StationPeople (station_interior_people.tscn)
Test 8 - Crash at StationPeople (station_interior_people.tscn)
Test 9 - Loads normally
Test 10 - Crash at StationObjects (station_interior_objects.tscn)

loading thread issues 4_resized

The current workaround: After identifying that StationObjects and StationPeople are the problematic scenes, I've opted to load them using the more straightforward load() command. Load() works 100% of the time on all scenes.

@eviltrout
Copy link

I have this exact same issue in my project. If I disable use_sub_threads it always loads properly but takes much longer. When it's active, it hangs randomly during development with no error. I just see my loading screen indefinitely.

@eviltrout
Copy link

eviltrout commented Jan 23, 2024

Update: I have found that if remove uses of preload for resources in my gdscript files it never hangs. There seems to be some issue with loading on sub_threads and preload.

Switching to load fixes the issues for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants