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

Native crash when loading in async function C# #63379

Open
Martanti opened this issue Jul 24, 2022 · 5 comments
Open

Native crash when loading in async function C# #63379

Martanti opened this issue Jul 24, 2022 · 5 comments

Comments

@Martanti
Copy link

Godot version

v3.4.4.stable.mono.official [419e713]

System information

Windows 10 64bit, OpenGL ES 3.0 Renderer: NVIDIA GeForce GTX 1060 with Max-Q Design/PCIe/SSE2 OpenGL ES Batching: ON

Issue description

When trying to call var loadedScene = GD.Load<PackedScene>(path); in a Task.Run within an async function the game crashed and the main godot console window printed out :

ERROR: FATAL: Index p_index = 10 is out of bounds (size() = 9).
   at: get (./core/cowdata.h:156)

=================================================================
        Native Crash Reporting
=================================================================
Got a UNKNOWN while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

=================================================================
        Managed Stacktrace:
=================================================================
=================================================================

Here are the logs:
2022-07-24_10.26.40_18036.log

Steps to reproduce

The ready function:

public override void _Ready()
	{
		_loadFinished = false;
		var dungeonSize = LevelConfig.DungeonSize;
		var powerLevel = LevelConfig.PowerLevel;
		var playerClass = LevelConfig.PlayerClass;

		// Having this in the async function also caused a window freezeup
		var scene = GD.Load<PackedScene>(
				_loadingScreenPath);
		_loadingScreen = scene.Instance();
		AddChild(_loadingScreen);

		_loadingScreenHandling = HandleLoadingScreenAsync();
		_levelLoading = LoadNewLevelAsync(dungeonSize, powerLevel, playerClass);
	}

The LoadNewLevelAsync:

private async Task LoadNewLevelAsync(
		double dungeonSize,
		double powerLevel,
		HeroClasses playerClass)
	{
		await Task.Run(() =>
		{
			// Load player
			LoadPlayer(playerClass);
		});
		_loadFinished = true;
	}

The LoadPlayer function, in which the crash happened:

private void LoadPlayer(HeroClasses playerClass)
	{
		var loadedScene = GD.Load<PackedScene>(_pathsToHeroPrefabs[playerClass]);
		var playerInstance = loadedScene.Instance();
		AddChild(playerInstance);
	}

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Jul 24, 2022

@Martanti Please upload a minimal reproduction project to make this easier to troubleshoot.

@tvardero

This comment was marked as off-topic.

@Martanti Martanti reopened this Jul 31, 2022
@Martanti
Copy link
Author

Martanti commented Jul 31, 2022

Sorry for the closing and reopening, miss-click.

@Calinou
So it seems that the issue is a composite. When trying to create a minimal reproduction project the async loading worked by itself. But then I introduced a rich text label with a custom font in a custom theme and that made the issue I was facing in my project. Tell me, if I need something more to add.

See the project attached below.
async breaking repro.zip

@tvardero after seeing some kind of correlation with using a custom theme with a font to the crash I am no longer sure if these two issues are related.

@tvardero
Copy link

Does the game crash when you make all your code synchronous? @Martanti

@Martanti
Copy link
Author

@tvardero I took the code from async calls and called them synchronously and it worked. Mind you, in one of the async calls I do have a while loop that waits for one bool to get set to true at the end of loading, so that was not executed.

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

3 participants