intjelic / esfml

SFML for supporting OpenGL ES available for smartphones/tablets
Other
34 stars 3 forks source link

android: example app crashes on startup #27

Open jonenst opened 11 years ago

jonenst commented 11 years ago

After compiling/installing esfml in android-ndk-r9, launching the android example on a nexus4 running cyanogenmod 10.1.2 (android 4.2.2) crashes.

However, launching the same app on the emulator didn't crash (the action bar disappeared and the screen remained white and there was some choppy sound)

Note that I was able to compile and run this project on the phone: http://code.google.com/p/android-native-egl-example/

I would love to help and debug if I can.

Following is the log in logcat:

08-07 23:50:00.666: D/libEGL(13867): loaded /system/lib/egl/libEGL_adreno200.so
08-07 23:50:00.666: D/libEGL(13867): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
08-07 23:50:00.676: D/libEGL(13867): loaded /system/lib/egl/libGLESv2_adreno200.so
08-07 23:50:00.686: I/Adreno200-EGL(13867): <eglInitialize:269>: EGL 1.4 QUALCOMM build: Nondeterministic AU_full_mako_PARTNER-ANDROID/JB-MR1-DEV_CL2961380_release_AU (CL2961380)
08-07 23:50:00.686: I/Adreno200-EGL(13867): Build Date: 12/10/12 Mon
08-07 23:50:00.686: I/Adreno200-EGL(13867): Local Branch: 
08-07 23:50:00.686: I/Adreno200-EGL(13867): Remote Branch: m/partner-android/jb-mr1-dev
08-07 23:50:00.686: I/Adreno200-EGL(13867): Local Patches: NONE
08-07 23:50:00.686: I/Adreno200-EGL(13867): Reconstruct Branch: NOTHING
08-07 23:50:01.206: W/Adreno200-EGL(13867): <eglMakeCurrent:2857>: EGL_BAD_ALLOC
08-07 23:50:01.206: E/libEGL(13867): eglMakeCurrent:593 error 3003 (EGL_BAD_ALLOC)
08-07 23:50:01.216: W/Adreno200-EGL(13867): <eglMakeCurrent:2857>: EGL_BAD_ALLOC
08-07 23:50:01.216: E/libEGL(13867): eglMakeCurrent:593 error 3003 (EGL_BAD_ALLOC)
[...] snip many lines like the errors above
intjelic commented 11 years ago

I recompiled the external dependencies for each architecture using the newer toolchain (GCC v4.8). Can you recompile SFML and your whole project to see if it still crashes ?

If your phone support ARM-v7a, use the right library. Make sure to pass the right arguments to CMake. For ARM-v7a, you'd need -DANDROID_ABI_ARMv7=1 and to be on the safe side (CMake files not polished yet, so unsure about their behavior) -DANDROID_ABI_ARM=0 (which disables ARM).

In your project's Application.mk: APP_ABI := armeabi-v7a

Use the -B argument to make sure everything is recompiled. $NDK/ndk-build -B

If that doesn't work, we'll need to work together :)

Thanks for your feedback!

jonenst commented 11 years ago

With the new binaries, I get the following linker error when trying to build the native part of the example android app after recompiling/reinstalling esfml:

Compile++ thumb  : sfml-activity <= main.cpp
SharedLibrary  : libsfml-activity.so
/home/jon/android-ndk-r9-smfl/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jon/android-ndk-r9-smfl/sources/sfml/extlibs/lib/armeabi/libopenal.a(opensl.o): in function opensl_reset_playback:/home/sonkun/Desktop/sfml-android-lib/build/openal-soft-android-master/Alc/backends/opensl.c:116: error: undefined reference to 'SL_IID_ANDROIDSIMPLEBUFFERQUEUE'
/home/jon/android-ndk-r9-smfl/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jon/android-ndk-r9-smfl/sources/sfml/extlibs/lib/armeabi/libopenal.a(opensl.o): in function opensl_open_playback:/home/sonkun/Desktop/sfml-android-lib/build/openal-soft-android-master/Alc/backends/opensl.c:198: error: undefined reference to 'slCreateEngine'
/home/jon/android-ndk-r9-smfl/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jon/android-ndk-r9-smfl/sources/sfml/extlibs/lib/armeabi/libopenal.a(opensl.o): in function opensl_open_playback:/home/sonkun/Desktop/sfml-android-lib/build/openal-soft-android-master/Alc/backends/opensl.c:213: error: undefined reference to 'SL_IID_ENGINE'
/home/jon/android-ndk-r9-smfl/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jon/android-ndk-r9-smfl/sources/sfml/extlibs/lib/armeabi/libopenal.a(opensl.o): in function opensl_start_playback:/home/sonkun/Desktop/sfml-android-lib/build/openal-soft-android-master/Alc/backends/opensl.c:377: error: undefined reference to 'SL_IID_BUFFERQUEUE'
/home/jon/android-ndk-r9-smfl/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: /home/jon/android-ndk-r9-smfl/sources/sfml/extlibs/lib/armeabi/libopenal.a(opensl.o): in function opensl_start_playback:/home/sonkun/Desktop/sfml-android-lib/build/openal-soft-android-master/Alc/backends/opensl.c:377: error: undefined reference to 'SL_IID_PLAY'
collect2: ld returned 1 exit status

My device is the nexus 4 with cyanogenmod's default kernel: shell@android:/ $ uname -a Linux localhost 3.4.0-perf-ga66bc09 #1 SMP PREEMPT Thu Jul 11 18:50:04 PDT 2013 armv7l GNU/Linux

jonenst commented 11 years ago

What is the example app suppose to look like ? Sound ? Graphics ?

MarioLiebisch commented 11 years ago

There's one dependency missing, I've fixed this in pull request/issue #32. Just check the changes I made on the example code (just note that sound playback seems to be broken with the latest version).

jonenst commented 11 years ago

Using https://github.com/MarioLiebisch/esfml/commit/87d0e5314310ff4af34ca94e2748bfc74c3a40a9 an android-ndk-9

I'm back to the following errors in logcat. 08-27 21:28:42.602: W/Adreno200-EGL(9950): eglMakeCurrent:2857: EGL_BAD_ALLOC 08-27 21:28:42.602: E/libEGL(9950): eglMakeCurrent:593 error 3003 (EGL_BAD_ALLOC)

On screen, there is an action bar with the SFML icon and "SFML" string. Below is a grey zone. No sound. Hitting back doesn't do anything until a popup allows to kill the app.

I didn't do anything related to ARM-v7a, because shell@android:/ $ uname -m
armv7l

What devices have you tested on ? What does the android example app do ?

Also, when generating the makefiles for the esfml build, I got the following warning, not sure if it's important:

 NDK=~/android-ndk-r9-smfl/ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchains/Android.cmake ..
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_TOOLCHAIN_FILE
MarioLiebisch commented 11 years ago

Wonder if that's related to Cyanogenmod or not. What happens if you strip all unnecessary lines from the example, i.e. running an empty window, not loading any textures or sounds? As for your CMake warning: I'm quite sure that's normal if there's already a CMakeCache.txt. Delete the file and try again, I bet the warning won't appear.

jonenst commented 11 years ago

You are right about the warning of CMake. the following main method still gives the EGL_BAD_ALLOC errors :

int main(int argc, char *argv[])
{
    sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "");
    while(true);
}

At some point a few days ago, I got the vanilla android example app to display the white screen and play sound correctly, but touching the screen never showed the sprites and the back button was not working and the app had to be force closed. I think this was when I used the new binaries that from the git repo, but had not recompiled the android example app.

I'll try and compare with the code for http://code.google.com/p/android-native-egl-example/ Do you have other ideas ?

MarioLiebisch commented 11 years ago

Softbuttons as well as hardware buttons shouldn't work right now. The only one working should be the Home button. That part is "intentional" so far.`

EGL_BAD_ALLOC: No idea. Maybe some race condition? Not really sure what you mean by using the new binaries without recompiling the example app.

jonenst commented 11 years ago

I mean I updated the binaries in esfml and my ndk (make and make install), but didn't run ndk-build in the example app, cleaned the java project in eclipse and ran again. If the new library binaries are in the .so made by ndk build (ie I was not using them at all), then this is some kind of heisenbug :/

Also, should there be a sleep in the main event loop, or are the display functions blocking? Le 27 août 2013 23:52, "Mario Liebisch" notifications@github.com a écrit :

Softbuttons as well as hardware buttons shouldn't work right now. The only one working should be the Home button. That part is "intentional" so far.`

EGL_BAD_ALLOC: No idea. Maybe some race condition? Not really sure what you mean by using the new binaries without recompiling the example app.

— Reply to this email directly or view it on GitHubhttps://github.com/Sonkun/esfml/issues/27#issuecomment-23374037 .

MarioLiebisch commented 11 years ago

You don't have to draw anything or update your window, but you'll have to process (well, poll) events. So using while(true); isn't really perfect, but should do the trick for testing (plus it might get optimized out due to being empty, for(;;) is the standards way to define an infinite blocking loop).

What you did (not running the NDK) essentially ignored the whole rebuilding of the library. Building the final APK (without running the NDK again) is just like linking a dynamic library on other systems (the one built before).

jonenst commented 11 years ago

I got it to work thanks to http://stackoverflow.com/questions/12443016/why-is-eglmakecurrent-failing-with-egl-bad-alloc

diff --git a/src/sfml/window/Android/EGLContext.cpp b/src/sfml/window/Android/EGLContext.cpp
index 31db24c..f8a4219 100644
--- a/src/sfml/window/Android/EGLContext.cpp
+++ b/src/sfml/window/Android/EGLContext.cpp
@@ -69,7 +69,11 @@ m_surface (EGL_NO_SURFACE)

     // Note: The EGL specs say that attrib_list can be NULL when passed to eglCreatePbufferSurface,
     // but this is resulting in a segfault. Bug in Android?
-    EGLint attrib_list[] = { EGL_NONE };
+    EGLint attrib_list[] = {
+      EGL_WIDTH, 1,
+      EGL_HEIGHT, 1,
+      EGL_NONE
+    };
     m_surface = eglCheck(eglCreatePbufferSurface(m_display, config[0], attrib_list));

     // Create the context

When I touch the screen, I get the sfml logo (with multitouch). Thanks.