Sfml: eglGetDisplay is NULL on Android

Created on 1 Feb 2020  Â·  8Comments  Â·  Source: SFML/SFML

I got SFML to compile, and am using sfml-activity in a NativeActivity:

<activity
            android:name="android.app.NativeActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name">
            <meta-data
                android:name="android.app.lib_name"
                android:value="sfml-activity" />
            <meta-data
                android:name="sfml.app.lib_name"
                android:value="myapp" />
        </activity>

On app startup, first it hits this line of code: https://github.com/SFML/SFML/blob/master/src/SFML/Main/SFMLActivity.cpp#L206

Which calls this one: https://github.com/SFML/SFML/blob/master/src/SFML/Main/MainAndroid.cpp#L495

The call to eglGetDisplay creates a segfault (segv_maperr in libc) when my app is starting up (before it even reaches int main). I tried to follow the chain and I found that this symbol is set to NULL: https://github.com/SFML/SFML/blob/master/extlibs/headers/glad/include/glad/egl.h#L1106

Later on in that include file, there are functions for initializing it. However, when I put breakpoints, it's not called: https://github.com/SFML/SFML/blob/master/src/SFML/Window/EglContext.cpp#L72

I tried playing around with the order of library linking (not sure if that would help or matter).

target_link_libraries( # Specifies the target library.
        myapp
        oboe
        NE10

        ${log-lib}
        android

        EGL
        GLESv1_CM

        sfml-system
        OpenAL

        sfml-window
        sfml-audio
        sfml-graphics
        sfml-network
        sfml-activity
        sfml-main)

Am I missing some step of GL/GLES init? Or perhaps app permissions to use EGL/Adreno GPU?

Android NDK version r20, ABI is arm64-v8a.

bug sfml-window android accepted

All 8 comments

Perhaps this is a problem:

W/AdrenoUtils: <ReadGpuID_from_sysfs:194>: Failed to open /sys/class/kgsl/kgsl-3d0/gpu_model
    <ReadGpuID:218>: Failed to read chip ID from gpu_model. Fallback to use the GSL path

I added some print statements:

  auto a = SF_GLAD_EGL_VERSION_1_0;
    auto b = SF_GLAD_EGL_VERSION_1_1;
    auto c = SF_GLAD_EGL_VERSION_1_2;
    auto d = SF_GLAD_EGL_VERSION_1_3;
    auto e = SF_GLAD_EGL_VERSION_1_4;
    auto f = SF_GLAD_EGL_VERSION_1_5;
    LOGI("sevag was here: %d %d %d %d %d %d", a, b, c, d, e, f);
    LOGI("this symbol is: %p", eglGetDisplay);
    states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

Result:

I/AUDIO-APP: sevag was here: 0 0 0 0 0 0
I/AUDIO-APP: this symbol is: 0x0
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 20264 (myapp), pid 20264 (myapp)
Process 20264 terminated.

I added one line, a call to gladLoaderLoadEGL(EGL_DEFAULT_DISPLAY);, and things work now:

    gladLoaderLoadEGL(EGL_DEFAULT_DISPLAY);
    auto a = SF_GLAD_EGL_VERSION_1_0;
    auto b = SF_GLAD_EGL_VERSION_1_1;
    auto c = SF_GLAD_EGL_VERSION_1_2;
    auto d = SF_GLAD_EGL_VERSION_1_3;
    auto e = SF_GLAD_EGL_VERSION_1_4;
    auto f = SF_GLAD_EGL_VERSION_1_5;
    LOGI("sevag was here: %d %d %d %d %d %d", a, b, c, d, e, f);
    LOGI("this symbol is: %p", eglGetDisplay);
    states->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);

Output:

I/AUDIO-APP: sevag was here: 1 1 1 1 1 1
    this symbol is: 0x7cee0e04d0
I/AudioEngine: EPG: we begin!
I/AAudio: AAudioStreamBuilder_openStream() called ----------------------------------------
I/AudioStreamBuilder: rate   =  48000, channels  = 1, format   = 5, sharing = EX, dir = INPUT
    device =      6, sessionId = -1, perfMode = 12, callback: ON with frames = 0
    usage  =      1, contentType = 2, inputPreset = 6, allowedCapturePolicy = 0
D/AudioStreamBuilder: build() EXCLUSIVE sharing mode not supported. Use SHARED.
D/: PlayerBase::PlayerBase()
I/AudioRecord: createRecord_l(0): AUDIO_INPUT_FLAG_FAST successful; frameCount 0 -> 4096
D/AudioStreamRecord: open() setup I16>FLOAT conversion buffer with 192 frames
W/AudioStreamRecord: open() flags changed from 0x00000005 to 0x00000001
I/AAudio: AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#1 ----------------
D/AAudio: AAudioStream_requestStart(s#1) called --------------
D/: PlayerBase::start() from IPlayer
D/AudioStreamLegacy: onAudioDeviceUpdate() devId 18 => 18
D/AAudio: AAudioStream_requestStart(s#1) returned 0 ---------
I/AudioEngine: EPG: we recording!
D/AudioStreamLegacy: onAudioDeviceUpdate() devId 18 => 18
E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
I/sfml-error: Warning: The created OpenGL context does not fully meet the settings that were requested
    Requested: version = 1.1 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
    Created: version = 0.0 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
    Failed to activate the window's context
    Failed to activate the window's context
I/sfml-error: Failed to activate the window's context
I/AudioEngine: EPG: entering main loop!
    EPG poll loop!
I/AudioEngine: MOUSE ENTERED!
I/sfml-error: Warning: The created OpenGL context does not fully meet the settings that were requested
    Requested: version = 1.1 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
    Created: version = 0.0 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
    Failed to activate the window's context
    Failed to activate the window's context
I/AudioEngine: GAINED FOCUS!
I/AUDIO-APP: BTrack: estimatedTempo: 120.000000
I/AudioEngine: EPG poll loop!
I/AUDIO-APP: BTrack: estimatedTempo: 120.000000

Hello, is there a solution?

I get the following error:

2020-08-25 17:49:32.447 3133-3133/? I/sfmldev.androi: Not late-enabling -Xcheck:jni (already on)
2020-08-25 17:49:32.474 3133-3133/? W/sfmldev.androi: Unexpected CPU variant for X86 using defaults: x86_64
2020-08-25 17:49:32.577 3133-3133/org.sfmldev.android W/System: ClassLoader referenced unknown path:
2020-08-25 17:49:32.643 3133-3133/org.sfmldev.android D/OpenGLRenderer: Skia GL Pipeline
2020-08-25 17:49:32.683 3133-3133/org.sfmldev.android E/libEGL: validate_display:94 error 3001 (EGL_NOT_INITIALIZED)
2020-08-25 17:49:32.688 3133-3133/org.sfmldev.android I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2020-08-25 17:49:32.688 3133-3133/org.sfmldev.android I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2020-08-25 17:49:33.233 3133-3174/org.sfmldev.android D/EGL_emulation: eglCreateContext: 0x7bbf8b072180: maj 1 min 0 rcv 1
2020-08-25 17:49:33.239 3133-3174/org.sfmldev.android D/EGL_emulation: eglMakeCurrent: 0x7bbf8b072180: ver 1 0 (tinfo 0x7bbf8b00d380)
2020-08-25 17:49:33.240 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x0000821b
2020-08-25 17:49:33.242 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x0000821c
2020-08-25 17:49:33.244 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x0000821e
2020-08-25 17:49:33.244 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x00009126
2020-08-25 17:49:33.245 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x0000821b
2020-08-25 17:49:33.249 3133-3174/org.sfmldev.android D/EGL_emulation: eglMakeCurrent: 0x7bbf8b072180: ver 1 0 (tinfo 0x7bbf8b00d380)
2020-08-25 17:49:33.253 3133-3174/org.sfmldev.android D/EGL_emulation: eglCreateContext: 0x7bbf8b072220: maj 1 min 0 rcv 1
2020-08-25 17:49:33.253 3133-3174/org.sfmldev.android E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
2020-08-25 17:49:33.254 3133-3174/org.sfmldev.android I/sfml-error: Warning: The created OpenGL context does not fully meet the settings that were requested
2020-08-25 17:49:33.254 3133-3174/org.sfmldev.android I/sfml-error: Requested: version = 1.1 ; depth bits = 0 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
2020-08-25 17:49:33.254 3133-3174/org.sfmldev.android I/sfml-error: Created: version = 0.0 ; depth bits = 24 ; stencil bits = 8 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
2020-08-25 17:49:33.254 3133-3174/org.sfmldev.android I/sfml-error: Failed to activate the window's context
2020-08-25 17:49:33.254 3133-3174/org.sfmldev.android I/sfml-error: Failed to activate the window's context
2020-08-25 17:49:33.255 3133-3174/org.sfmldev.android D/EGL_emulation: eglMakeCurrent: 0x7bbf8b072180: ver 1 0 (tinfo 0x7bbf8b00d380)
2020-08-25 17:49:33.274 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x0000821b
2020-08-25 17:49:33.274 3133-3174/org.sfmldev.android E/eglCodecCommon: glUtilsParamSize: unknow param 0x0000821c
2020-08-25 17:49:33.288 3133-3174/org.sfmldev.android D/EGL_emulation: eglMakeCurrent: 0x7bbf8b072180: ver 1 0 (tinfo 0x7bbf8b00d380)

--------- beginning of crash

2020-08-25 17:49:33.289 3133-3174/org.sfmldev.android A/libc: Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7bbf7ca71550 in tid 3174 (sfmldev.android), pid 3133 (sfmldev.android)

It keeps prompting that opengl is not initialized, and I am not good at opengl. . .

@sevagh I didn't fully understand this, where exactly did you add gladLoaderLoadEGL(EGL_DEFAULT_DISPLAY);?

@eXpl0it3r you can see my commit (to the Android app source code) here: https://github.com/sevagh/ElectroPARTYogram/commit/96e9d9e5c619a03faaa54f443d224f0d2be0dc51#diff-37bf2c59ebc2b07df4acb6df16d6fd006ae639c855a4bd65547edbc09932d673
I have a vendored copy of of SFML, and I added the change to SFML/src/SFML/Main/MainAndroid.cpp

Ah okay, would you be willing to provide a PR for this?

Fixed with #1740

Was this page helpful?
0 / 5 - 0 ratings