stride3d / stride

Stride (formerly Xenko), a free and open-source cross-platform C# game engine.
https://stride3d.net
MIT License
6.62k stars 957 forks source link

Android emulator startup texture setup crash #2259

Closed Basewq closed 5 months ago

Basewq commented 5 months ago

Release Type: Official Release

Version: 4.2.0.2122

Platform(s): Android

Describe the bug SpaceEscape, TopDownRPG & 'New game' templates crash when deploying Debug build to Android emulator with the following error:

[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindBuffer:551 GL error 0x500
[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBufferData:576 GL error 0x500
[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindBuffer:551 GL error 0x500
[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindBuffer:551 GL error 0x500
[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBufferData:576 GL error 0x500
[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glBindBuffer:551 GL error 0x500
[emuglGLESv2_enc] device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glFramebufferTexture2D:2723 GL error 0x500
**System.InvalidOperationException:** 'FBO is incomplete: 1 RTs: [RT0: 2]; Depth 1 (error: FramebufferIncompleteAttachment)'

[Stride] [Game]: Error: Unexpected exception. System.InvalidOperationException: FBO is incomplete: 1 RTs: [RT0: 2]; Depth 1 (error: FramebufferIncompleteAttachment)
[Stride]    at Stride.Graphics.GraphicsDevice.GenerateFBO(FBOTexture depthStencilBuffer, FBOTexture[] renderTargets, Int32 renderTargetCount) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\GraphicsDevice.OpenGL.cs:line 395
[Stride]    at Stride.Graphics.GraphicsDevice.FindOrCreateFBO(FBOTexture depthStencilBuffer, FBOTexture[] renderTargets, Int32 renderTargetCount) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\GraphicsDevice.OpenGL.cs:line 438
[Stride]    at Stride.Graphics.CommandList.SetupTargets() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\CommandList.OpenGL.cs:line 1373
[Stride]    at Stride.Graphics.CommandList.SetRenderTargetsImpl(Texture depthStencilBuffer, Int32 renderTargetCount, Texture[] renderTargets) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\CommandList.OpenGL.cs:line 1257
[Stride]    at Stride.Graphics.CommandList.CommonSetRenderTargetsAndViewport(Texture depthStencilView, Int32 currentRenderTargetCount, Texture[] renderTargetViews) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\CommandList.cs:line 346
[Stride]    at Stride.Graphics.CommandList.SetRenderTargetAndViewport(Texture depthStencilView, Texture renderTargetView) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\CommandList.cs:line 193
[Stride]    at Stride.Graphics.CommandList.ClearState() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\CommandList.cs:line 88
[Stride]    at Stride.Games.GameBase.BeginDraw() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Games\GameBase.cs:line 773
[Stride]    at Stride.Games.GameBase.InitializeBeforeRun() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Games\GameBase.cs:line 372System.InvalidOperationException: FBO is incomplete: 1 RTs: [RT0: 2]; Depth 1 (error: FramebufferIncompleteAttachment)
[Stride]    at Stride.Graphics.GraphicsDevice.GenerateFBO(FBOTexture depthStencilBuffer, FBOTexture[] renderTargets, Int32 renderTargetCount) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\GraphicsDevice.OpenGL.cs:line 395
[Stride]    at Stride.Graphics.GraphicsDevice.FindOrCreateFBO(FBOTexture depthStencilBuffer, FBOTexture[] renderTargets, Int32 renderTargetCount) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\GraphicsDevice.OpenGL.cs:line 438
[Stride]    at Stride.Graphics.CommandList.SetupTargets() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\CommandList.OpenGL.cs:line 1373
[Stride]    at Stride.Graphics.CommandList.SetRenderTargetsImpl(Texture depthStencilBuffer, Int32 renderTargetCount, Texture[] renderTargets) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\OpenGL\CommandList.OpenGL.cs:line 1257
[Stride]    at Stride.Graphics.CommandList.CommonSetRenderTargetsAndViewport(Texture depthStencilView, Int32 currentRenderTargetCount, Texture[] renderTargetViews) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\CommandList.cs:line 346
[Stride]    at Stride.Graphics.CommandList.SetRenderTargetAndViewport(Texture depthStencilView, Texture renderTargetView) in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\CommandList.cs:line 193
[Stride]    at Stride.Graphics.CommandList.ClearState() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Graphics\CommandList.cs:line 88
[Stride]    at Stride.Games.GameBase.BeginDraw() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Games\GameBase.cs:line 773
[Stride]    at Stride.Games.GameBase.InitializeBeforeRun() in C:\BuildAgent\work\b5f46e3c4829a09e\sources\engine\Stride.Games\GameBase.cs:line 372

Android Emulator used: Android 10/Api 29, x86_64

Note that when using Android 13/Api 33, x86_64, only a black screen appears for New game & TopDownRPG templates, with no exception thrown, however SpaceEscape does work. As a side note, it would only run in Api 33 with the Bluetooth permissions as per the solution discussed here. The bluetooth solution is not required if just running/testing on Api 29.

To Reproduce Steps to reproduce the behavior:

  1. In Android Device Manager, create Android 10, processor x86_64
  2. Create New game template with Android project.
  3. Deploy the game to the emulator & run game

Expected behavior Not error

Additional context SpaceEscape being the only project working, and only on the Api33 version is interesting outlier. SpaceEscape uses different Graphics Compositor settings which may hint at the different render texture(s) being set: SpaceEscape (Also note it uses a different main shader Effect.)

New game project Graphics Compositor settings: MyGame

My speculation is the newer Android version just silently suppressed this error, which might be why you just get a black screen (though SpaceEscape working for Api 33 might debunk this theory).

MeharDT commented 5 months ago

A target API of 34 is required in .NET 8.0, although it wouldn't explain why Space Escape sometimes works for you with API 33.

@Ethereal77 mentions here that they found issues in the Silk.net integration, maybe they can provide some insights on the OpenGL exception in your log.

https://github.com/stride3d/stride/issues/2008#issuecomment-2118745380

Basewq commented 5 months ago

A target API of 34 is required in .NET 8.0, although it wouldn't explain why Space Escape sometimes works for you with API 33.

To clarify, the doc here (though it says it's for MAUI, the android csproj settings are relevant to xamarin). The Stride projects specify the following:

Target API & minimum API are different things. There shouldn't be any issues specifically with the emulator's api (otherwise Android would reject installing them if they don't meet the min api level). I have SDK for api 34 installed, and have uploaded non-Stride Android Xamarin on the Google Play Store - believe me, they auto-detect & reject your app if your target api isn't correct, so I know the Stride apps will be building with target api 34.

Yes, it's probably a Silk integration issue, though don't really have time to investigate further at the moment. Hopefully this be might enough to hint for anyone else wanting to look into it (eg. searching 'OpenGL FramebufferIncompleteAttachment' comes up with 100 different issues and solutions, lol)

Ethereal77 commented 5 months ago

@Ethereal77 mentions here that they found issues in the Silk.net integration, maybe they can provide some insights on the OpenGL exception in your log.

To clarify, in that comment I'm talking about DirectX. The problems I've encountered were in the use of the API in certain scenarios. Nothing specific to Silk.NET and not related to OpenGL or Vulkan, which is what Android would use.

Basewq commented 5 months ago

Quick minor update based on what I've found, which I'll need to expand on in the future when I have time.

Graphics API 'OpenGL ES 2' and less is not supported on an engine level so probably needs to be documented for Stride developers using Android. There used to be code for emulating 'Uniform Buffers' on OpenGL ES 2, but was cut out, so the engine failed to generate any buffers of this nature (this is the shader cbuffer stuff, so deeply embedded into the engine). Not exactly sure what's the relationship between this and Framebuffer texture error, it could just be a snowball effect, since the engine actually does some 'uniform buffer' setup before this particular error (also this is an engine thrown exception after checking the GL api state, whereas the 'uniform buffer' ones are not checked).

The Android 10/Api 29 emulator did not support ES 3 on my machine, so at some point failed (though not immediately), since some of the GL calls are not constantly checking if the GL calls failed or not. Even though I've set up the Stride Game Settings to be OpenGL ES 3, if the hardware doesn't support it, then Stride will drop your settings to ES 2 - but as stated before ES 2 is not supported. Developers are most likely going to need to check the hardware's ES version and prevent the app from continuing if not done on an engine level.

After making a debug build of the Stride code, the Android 13/Api 33 tested on New game worked after a while, it took a long time because it was building the shaders - will need to recheck what's the deal with the official release version, there might be some multithreaded GL api call running over each other, or it just might be slow as well. Didn't retest TopDownRPG yet.

Basewq commented 5 months ago

Issue has been properly identified by #2283 with a workaround.