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

Android .NET 6.0 CreateOpenGLES() failed to get the default Android EGLDisplay #456

Open
eightonegulf opened this issue Jul 16, 2022 · 3 comments

Comments

@eightonegulf
Copy link

Hi,
I'm trying to setup Veldrid within an Android .NET 6.0 application.
My MainActivity class looks as follow:

    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle? savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            GraphicsDeviceOptions options = new GraphicsDeviceOptions(
                false,
                PixelFormat.R16_UNorm,
                false,
                ResourceBindingModel.Improved,
                true,
                true);
            var surface = new VeldridSurfaceView(this, Veldrid.GraphicsBackend.OpenGLES, options);
            SetContentView(surface);
        }
    }

The VeldridSurfaceView is directly copied from
https://github.com/mellinoe/veldrid-samples/blob/master/src/SampleBase.Android/VeldridSurfaceView.cs

When I run this on my Android device, line #84 in VeldridSurfaceView GraphicsDevice = GraphicsDevice.CreateOpenGLES(DeviceOptions, sd); will throw an exception stating;

CreateOpenGLES() failed to get the default Android EGLDisplay: BadParameter

This exception originates from https://github.com/mellinoe/veldrid/blob/master/src/Veldrid/OpenGL/OpenGLGraphicsDevice.cs
InitializeANativeWindow(), line #621.
For some reason the display can't be found.

When I run exactly the same code from an Xamarin Android app, everything works as expected, and I can use Veldrid just fine.
Only when I run from a .NET 6.0 app this goes wrong.

I am using VS 2022 Preview in order to use .NET 6.0 on Android.

I can't figure out what I'm missing. Is this a compatability issue, or am I missing something else?

Thanks.

@0x5b25
Copy link

0x5b25 commented Aug 11, 2022

Hi, that might be caused by the wrong eglGetDisplay signature in EGLNative.cs, the actual c function requires a argument of pointer type , but the C# wrapper supplies a System.Int32 type, on 64-bit Android OS (which is the majority now) this causes a invalid argument exception because the upper 32 bit half is just rubbish data.

The fix is also very simple, just clone the repo, add a local project reference, and change IntPtr eglGetDisplay(int native_display) to IntPtr eglGetDisplay(IntPtr native_display), and everything will be fine

@mellinoe
Copy link
Collaborator

It would be great to confirm if @0x5b25 's change does indeed fix it. I don't have an active Android setup right now so this will take a bit for me to debug.

@xtuzy
Copy link

xtuzy commented Nov 13, 2022

Use IntPtr fixed it
sharex-20221113154438

xtuzy added a commit to xtuzy/veldrid.maui that referenced this issue Nov 20, 2022
dtatarnikov added a commit to dtatarnikov/veldrid that referenced this issue Jul 6, 2023
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