Android: Crash on change of orientation
Polybios

(Disclaimer: I don't have much experience with Android development.)

While playing around with porting my project to Android using the new Android Studio based building process described here, I've encountered a crash (SIGSEGV) whenever I change the orientation of the display. A backtrace that is apparently not very helpful seems to tell me there is a nullptr being accessed:

(lldb) bt
* thread #1: tid = 3754, 0xa2d864cc liballegro.so, name = 'nemo.uitest', 
stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0xa2d864cc liballegro.so
  * frame #1: 0xaf238088 libnative-lib.so`(anonymous namespace)::__future_category_instance()::__fec + 4

I successfully built an older version of the same app using the old CMake/ant/ndk-build (?) based toolchain some months ago where this crash does not occur.

To investigate, I've built the Android example (allegro5/android/example/) from current git once using the new Android studio based system and once using the old CMake/... based system. The example built using the new build system will disappear into the background as soon as I turn the phone (the AllegroActivity gets destroyed and the debugger reports it as DEAD) and will only be accessible again when I select it from the menu of running apps by pressing the phone's button (?).
The example built using the old build system appears to correctly change orientation of the display and will not go into background or crash.

Could this be related to using the wrong version of some SDK?

From what I can see, my Android Studio installation seems to build with API 25 (Android 7.1.1 (Nougat)) and build tools version 25.0.0. The old native-sdk toolchain was set up with API 22 I think.

I'd be glad for some advice on this! :)

Edit: No ideas, anyone? ???

Edgar Reynaldo

Does allegro send an ALLEGRO_EVENT_DISPLAY_RESIZED event when the orientation changes? If so, are you acknowledging it?

EDIT
I guess there is an ALLEGRO_EVENT_DISPLAY_ORIENTATION event. Does it crash before or after this event occurs?

EDIT2
You may also want to monitor ALLEGRO_EVENT_DISPLAY_HALT_DRAWING. Allegro will crash if you attempt to draw after acknowledging this event before receiving and acknowledging an ALLEGRO_EVENT_DISPLAY_RESUME_DRAWING event.

Polybios

The funny thing is I don't seem to get any of these events.

I've compiled the Android example (allegro5/android/example/csrc/main.c) with the new Android Studio method (just copy-pasting it into native-lib.cpp). This appears to crash, too, just without a SIGSEGV.

Since I don't know how to make the ALLEGRO_DEBUG messages actually appear, I redefined these to use

#define ALLEGRO_DEBUG(...)  __android_log_print(ANDROID_LOG_DEBUG,"ALLEGRO_DEBUG_main",__VA_ARGS__)

You see there are ALLEGRO_DEBUGs on almost every event in the Android example, I've added one for ALLEGRO_EVENT_DISPLAY_ORIENTATION, too.

But when I turn the phone, all I get is this:

11-03 23:36:37.850 15309-15309/nemo.allegrotest D/AllegroActivity: onPause
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onPause end
11-03 23:36:37.870 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onSaveInstanceState
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onStop.
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onDestroy

Full log:

11-03 23:36:30.142 15309-15309/? I/art: Late-enabling -Xcheck:jni
11-03 23:36:30.203 15309-15309/? W/XPrivacy: Hooking package=nemo.allegrotest
11-03 23:36:30.293 15309-15309/nemo.allegrotest W/linker: liballegro.so: unused DT entry: type 0x6ffffffe arg 0xd0dc
11-03 23:36:30.293 15309-15309/nemo.allegrotest W/linker: liballegro.so: unused DT entry: type 0x6fffffff arg 0x3
11-03 23:36:30.303 15309-15309/nemo.allegrotest W/linker: liballegro_primitives.so: unused DT entry: type 0x6ffffffe arg 0x2418
11-03 23:36:30.303 15309-15309/nemo.allegrotest W/linker: liballegro_primitives.so: unused DT entry: type 0x6fffffff arg 0x2
11-03 23:36:30.303 15309-15309/nemo.allegrotest W/linker: liballegro_image.so: unused DT entry: type 0x6ffffffe arg 0xfe0
11-03 23:36:30.303 15309-15309/nemo.allegrotest W/linker: liballegro_image.so: unused DT entry: type 0x6fffffff arg 0x1
11-03 23:36:30.313 15309-15309/nemo.allegrotest W/linker: liballegro_font.so: unused DT entry: type 0x6ffffffe arg 0x139c
11-03 23:36:30.313 15309-15309/nemo.allegrotest W/linker: liballegro_font.so: unused DT entry: type 0x6fffffff arg 0x2
11-03 23:36:30.313 15309-15309/nemo.allegrotest W/linker: liballegro_ttf.so: unused DT entry: type 0x6ffffffe arg 0x59ac
11-03 23:36:30.313 15309-15309/nemo.allegrotest W/linker: liballegro_ttf.so: unused DT entry: type 0x6fffffff arg 0x1
11-03 23:36:30.313 15309-15309/nemo.allegrotest W/linker: liballegro_audio.so: unused DT entry: type 0x6ffffffe arg 0x29ec
11-03 23:36:30.313 15309-15309/nemo.allegrotest W/linker: liballegro_audio.so: unused DT entry: type 0x6fffffff arg 0x2
11-03 23:36:30.333 15309-15309/nemo.allegrotest W/linker: liballegro_acodec.so: unused DT entry: type 0x6ffffffe arg 0x4318
11-03 23:36:30.333 15309-15309/nemo.allegrotest W/linker: liballegro_acodec.so: unused DT entry: type 0x6fffffff arg 0x2
11-03 23:36:30.333 15309-15309/nemo.allegrotest W/linker: liballegro_color.so: unused DT entry: type 0x6ffffffe arg 0x6ec
11-03 23:36:30.333 15309-15309/nemo.allegrotest W/linker: liballegro_color.so: unused DT entry: type 0x6fffffff arg 0x2
11-03 23:36:30.343 15309-15309/nemo.allegrotest D/AllegroActivity: Number of input devices: 9
11-03 23:36:30.363 15309-15309/nemo.allegrotest D/AllegroActivity: onCreate
11-03 23:36:30.363 15309-15309/nemo.allegrotest D/AllegroActivity: Files Dir: /data/data/nemo.allegrotest/files
11-03 23:36:30.373 15309-15309/nemo.allegrotest D/AllegroActivity: External Storage Dir: /storage/emulated/0
11-03 23:36:30.393 15309-15309/nemo.allegrotest D/AllegroActivity: External Files Dir: /storage/emulated/0/Android/data/nemo.allegrotest/files
11-03 23:36:30.393 15309-15309/nemo.allegrotest D/AllegroActivity: external: avail = true writable = true
11-03 23:36:30.393 15309-15309/nemo.allegrotest D/AllegroActivity: sourceDir: /data/app/nemo.allegrotest-1/base.apk
11-03 23:36:30.393 15309-15309/nemo.allegrotest D/AllegroActivity: publicSourceDir: /data/app/nemo.allegrotest-1/base.apk
11-03 23:36:30.403 15309-15309/nemo.allegrotest D/AllegroActivity: before nativeOnCreate
11-03 23:36:30.403 15309-15309/nemo.allegrotest W/linker: libnative-lib.so: unused DT entry: type 0x6ffffffe arg 0xc38
11-03 23:36:30.403 15309-15309/nemo.allegrotest W/linker: libnative-lib.so: unused DT entry: type 0x6fffffff arg 0x1
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: init allegro!
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: init primitives
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: init image addon
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: init touch input
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: init keyboard
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: creating display
11-03 23:36:30.413 15309-15343/nemo.allegrotest D/AllegroActivity: postCreateSurface
11-03 23:36:30.413 15309-15309/nemo.allegrotest D/AllegroActivity: onCreate end
11-03 23:36:30.413 15309-15309/nemo.allegrotest D/AllegroActivity: onStart.
11-03 23:36:30.413 15309-15309/nemo.allegrotest D/AllegroActivity: onResume
11-03 23:36:30.423 15309-15309/nemo.allegrotest D/AllegroActivity: postCreateSurface
11-03 23:36:30.423 15309-15309/nemo.allegrotest D/AllegroActivity: Number of input devices: 9
11-03 23:36:30.423 15309-15309/nemo.allegrotest D/AllegroActivity: onResume end
11-03 23:36:30.453 15309-15344/nemo.allegrotest D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
11-03 23:36:30.463 15309-15309/nemo.allegrotest D/Atlas: Validating map...
11-03 23:36:30.473 15309-15309/nemo.allegrotest D/AllegroActivity: createSurface
11-03 23:36:30.473 15309-15309/nemo.allegrotest D/AllegroSurface: PixelFormat=1
11-03 23:36:30.473 15309-15309/nemo.allegrotest D/AllegroActivity: createSurface end
11-03 23:36:30.483 15309-15309/nemo.allegrotest D/AllegroActivity: createSurface
11-03 23:36:30.483 15309-15309/nemo.allegrotest D/AllegroSurface: PixelFormat=1
11-03 23:36:30.483 15309-15309/nemo.allegrotest D/AllegroActivity: createSurface end
11-03 23:36:30.503 15309-15344/nemo.allegrotest I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.AF.1.1.04.04.03.164.081_msm8960_LA.AF.1.1__release_AU ()
                                                              OpenGL ES Shader Compiler Version: E031.25.01.03
                                                              Build Date: 11/02/14 Sun
                                                              Local Branch: mybranch5454281
                                                              Remote Branch: quic/l_LNX.LA.3.6
                                                              Local Patches: NONE
                                                              Reconstruct Branch: AU_LINUX_ANDROID_LA.AF.1.1.04.04.03.164.081 + db92d1e + cb8de02 +  NOTHING
11-03 23:36:30.503 15309-15344/nemo.allegrotest I/OpenGLRenderer: Initialized EGL, version 1.4
11-03 23:36:30.533 15309-15344/nemo.allegrotest D/OpenGLRenderer: Enabling debug mode 0
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroSurface: surfaceCreated
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroSurface: Grabbing focus
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroSurface: surfaceCreated end
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroSurface: surfaceChanged (width=1080 height=1920)
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroEGL: egl_Init
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroEGL: egl_Init end
11-03 23:36:30.603 15309-15309/nemo.allegrotest D/AllegroEGL: eglChooseConfig returned 20 configurations.
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 0
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 1
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 2
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 3
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 4
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 5
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 6
11-03 23:36:30.613 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 7
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 8
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 9
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 10
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 11
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 12
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 13
11-03 23:36:30.623 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 14
11-03 23:36:30.633 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 15
11-03 23:36:30.633 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 16
11-03 23:36:30.633 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 17
11-03 23:36:30.633 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 18
11-03 23:36:30.633 15309-15309/nemo.allegrotest D/AllegroEGL: Getting attribs for config at index 19
11-03 23:36:30.633 15309-15309/nemo.allegrotest D/AllegroEGL: egl_createContext
11-03 23:36:30.643 15309-15309/nemo.allegrotest D/AllegroEGL: EGL context created
11-03 23:36:30.643 15309-15309/nemo.allegrotest D/AllegroEGL: egl_createContext end
11-03 23:36:30.643 15309-15309/nemo.allegrotest D/AllegroEGL: created new surface: com.google.android.gles_jni.EGLSurfaceImpl@4b4fd32e
11-03 23:36:30.643 15309-15309/nemo.allegrotest D/AllegroEGL: egl_clearCurrent
11-03 23:36:30.653 15309-15309/nemo.allegrotest D/AllegroEGL: egl_clearCurrent done
11-03 23:36:30.653 15309-15309/nemo.allegrotest D/AllegroSurface: surfaceChanged end
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/AllegroEGL: egl_clearCurrent
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/AllegroEGL: egl_clearCurrent done
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/AllegroEGL: egl_clearCurrent
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/AllegroEGL: egl_clearCurrent done
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_RESOURCES_PATH: data/data/nemo.allegrotest/files
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_TEMP_PATH: data/data/nemo.allegrotest/files
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_USER_DATA_PATH: data/data/nemo.allegrotest/files
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_USER_HOME_PATH: data/data/nemo.allegrotest/files
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_USER_SETTINGS_PATH: data/data/nemo.allegrotest/files
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_USER_DOCUMENTS_PATH: data/data/nemo.allegrotest/files
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: ALLEGRO_EXENAME_PATH: /data/app/nemo.allegrotest-1/base.apk
11-03 23:36:30.653 15309-15343/nemo.allegrotest D/ImageLoader: decodeBitmapAsset begin
11-03 23:36:30.663 15309-15343/nemo.allegrotest D/ImageLoader: done waiting for decodeStream
11-03 23:36:30.663 15309-15343/nemo.allegrotest D/ImageLoader: decodeBitmapAsset end
11-03 23:36:30.673 15309-15343/nemo.allegrotest D/AllegroInputStream: ctor handle:-1262505408
11-03 23:36:30.673 15309-15343/nemo.allegrotest D/ImageLoader: decodeBitmapStream begin
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 4
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 4
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 4
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 4
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 8
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 8
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 13
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 13
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 4
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 4
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 8
11-03 23:36:30.683 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 8
[... lots more about reading from a stream ...]
11-03 23:36:30.723 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.723 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.743 15309-15319/nemo.allegrotest W/art: Suspending all threads took: 7.781ms
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.743 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 3
11-03 23:36:30.753 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 3
11-03 23:36:30.753 15309-15309/nemo.allegrotest I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@35e65143 time:45488862
[... and even more ...]
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 6069
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 6069
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 4
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 4
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 8
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 8
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read handle: -1262505408, offset: 0, length: 4
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/AllegroInputStream: read end: ret = 4
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/ImageLoader: done waiting for decodeStream
11-03 23:36:30.833 15309-15343/nemo.allegrotest D/ImageLoader: decodeBitmapStream end
11-03 23:36:30.873 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:31.864 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:31.874 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:32.865 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:32.895 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:33.866 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:33.896 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:34.857 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:34.897 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:35.508 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: touch 0 begin
11-03 23:36:35.628 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: touch 0 end
11-03 23:36:35.858 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:35.908 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:36.859 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:36.909 15309-15343/nemo.allegrotest E/libEGL: called unimplemented OpenGL ES API
11-03 23:36:37.850 15309-15309/nemo.allegrotest D/AllegroActivity: onPause
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onPause end
11-03 23:36:37.870 15309-15343/nemo.allegrotest D/ALLEGRO_DEBUG_main: tick
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onSaveInstanceState
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onStop.
11-03 23:36:37.870 15309-15309/nemo.allegrotest D/AllegroActivity: onDestroy

Edgar Reynaldo
Polybios said:

onDestroy

It's crashing inside nativeOnDestroy, according to your debug logs :

AllegroActivity.java#SelectExpand
395 /** Called when the activity is destroyed */ 396 @Override 397 public void onDestroy() 398 { 399 super.onDestroy(); 400 Log.d("AllegroActivity", "onDestroy"); 401 402 nativeOnDestroy(); 403 Log.d("AllegroActivity", "onDestroy end"); 404 }

That's all the help I can give you for now. I don't know much else. Try looking up the nativeOnDestroy function and see where it takes you.

Polybios

Well, I'm not sure, but I doubt the AllegroActivity should be destroyed at all when turning the phone. ???

Edit:
Okay, I've investigated this further.
Now I've taken the opportunity to update my phone to Android 6.0 (i.e. CyanogenMod 13).
After that I've installed all the version 23 SDKs and tools and compiled the Android example again using Android Studio with these SDKs. I get the same behavior.

Then I've created a standalone ndk-toolchain using these SDKs and compiled Allegro (from current git) for Android again using this toolchain.
Started the Android example... It works without problems when turning the phone.
I can also see it seems to react properly to all relevant events via logcat (can see the ALLEGRO_DEBUGs there, too).

So this seems to confirm there is something wrong with the Gradle based (?) build system.

Edgar Reynaldo

It could be throwing an exception, which when caught, triggers the onDestroy method, and for some reason it crashes inside there.

Elias

Android destroys all activities of all apps when the device rotates.

Polybios

Edit: Tested this with another device, used API 24 this time as the binaries on the maven repository seem to use this.

Still no proper orientation change in Android example, but the AllegroActivity is destroyed without the orientation change actually happening, app seems to go to background. Resumes (actually, starts again?) with the old orientation when selected from the menu of running apps.

I'd be grateful for any advice on how to narrow down or resolve this problem.
Hasn't anyone else tried the new binaries from the repository?

------------------

Original post:

Ok... I can't see onDestroy in the log of the Android example built from the commandline with the native toolchain, however (the one that seems to process orientation change correctly).

When changing the orientation of the phone here, there's no sequence of onPause, onSaveInstanceState, onDestroy in the log, but rather onConfigurationChanged, followed by orientation changed.
No onDestroy. As this log is more verbose anyway, I doubt it got missed somehow.

Maybe it would be interesting to run the gradle-built example with the same debug level... However, I don't know if and how this could be achieved.

Log:

11-06 09:13:29.861 23618 23642 E libEGL  : called unimplemented OpenGL ES API
11-06 09:13:30.762 23618 23642 I allegro : main     D 23642:               main.c:172  main                             [  11.30466] tick
11-06 09:13:30.869 23618 23618 D AllegroActivity: onConfigurationChanged
11-06 09:13:30.869 23618 23618 D AllegroActivity: changes: 10010000000
11-06 09:13:30.869 23618 23618 D AllegroActivity: orientation changed
11-06 09:13:30.870 23618 23618 I allegro : android  D 23618:     android_system.c:416  Java_org_liballeg_android_AllegroActivity_nativeOnOrientationChange [  11.41284] got orientation change!
11-06 09:13:30.870 23618 23618 I allegro : android  D 23618:     android_system.c:431  Java_org_liballeg_android_AllegroActivity_nativeOnOrientationChange [  11.41290] locking display event source: 0xb4a0ae00 0xb4a0ae00
11-06 09:13:30.870 23618 23618 I allegro : android  D 23618:     android_system.c:436  Java_org_liballeg_android_AllegroActivity_nativeOnOrientationChange [  11.41296] emit event
11-06 09:13:30.870 23618 23618 I allegro : android  D 23618:     android_system.c:443  Java_org_liballeg_android_AllegroActivity_nativeOnOrientationChange [  11.41302] unlocking display event source
11-06 09:13:30.870 23618 23618 D AllegroActivity: old orientation: 1, new orientation: 2
11-06 09:13:30.927 23618 23642 E libEGL  : called unimplemented OpenGL ES API
11-06 09:13:31.087 23618 23618 D AllegroSurface: surfaceChanged (width=1920 height=1080)
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:121  Java_org_liballeg_android_AllegroSurface_nativeOnChange [  11.62982] on change 1920x1080!
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:315  _al_android_resize_display       [  11.62988] display resize
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:320  _al_android_resize_display       [  11.62991] locking mutex
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:322  _al_android_resize_display       [  11.62997] done locking mutex
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:324  _al_android_resize_display       [  11.63001] locking display event source: 0xb4a0ae00
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:327  _al_android_resize_display       [  11.63007] check generate event
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:343  _al_android_resize_display       [  11.63013] unlocking display event source
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:347  _al_android_resize_display       [  11.63019] waiting for display resize acknowledge
11-06 09:13:31.087 23618 23618 I allegro : display  D 23618:    android_display.c:349  _al_android_resize_display       [  11.63025] calling al_wait_cond
11-06 09:13:31.087 23618 23642 I allegro : main     D 23642:               main.c:203  main                             [  11.63031] display resize
11-06 09:13:31.087 23618 23642 I allegro : display  D 23642:    android_display.c:684  android_acknowledge_resize       [  11.63037] clear current context
11-06 09:13:31.087 23618 23642 D AllegroEGL: egl_clearCurrent
11-06 09:13:31.088 23618 23642 D AllegroEGL: egl_clearCurrent done
11-06 09:13:31.088 23618 23642 I allegro : display  D 23642:    android_display.c:687  android_acknowledge_resize       [  11.63089] locking mutex
11-06 09:13:31.088 23618 23642 I allegro : display  D 23642:    android_display.c:691  android_acknowledge_resize       [  11.63095] broadcasted condvar
11-06 09:13:31.088 23618 23642 I allegro : display  D 23642:    android_display.c:693  android_acknowledge_resize       [  11.63098] waiting for display resize acknowledge 2
11-06 09:13:31.088 23618 23642 I allegro : display  D 23642:    android_display.c:695  android_acknowledge_resize       [  11.63104] calling al_wait_cond
11-06 09:13:31.088 23618 23618 I allegro : display  D 23618:    android_display.c:353  _al_android_resize_display       [  11.63132] done waiting for display resize acknowledge
11-06 09:13:31.088 23618 23618 I allegro : display  D 23618:    android_display.c:359  _al_android_resize_display       [  11.63138] resize backbuffer
11-06 09:13:31.088 23618 23618 I allegro : display  D 23618:    android_display.c:369  _al_android_resize_display       [  11.63144] done
11-06 09:13:31.088 23618 23618 D AllegroSurface: surfaceChanged end
11-06 09:13:31.089 23618 23642 I allegro : display  D 23642:    android_display.c:699  android_acknowledge_resize       [  11.63226] done waiting for display resize acknowledge 2
11-06 09:13:31.089 23618 23642 I allegro : display  D 23642:    android_display.c:701  android_acknowledge_resize       [  11.63232] acquire context
11-06 09:13:31.089 23618 23642 I allegro : display  D 23642:    android_display.c:704  android_acknowledge_resize       [  11.63251] done
11-06 09:13:31.090 23618 23642 I allegro : main     D 23642:               main.c:205  main                             [  11.63254] done resize
11-06 09:13:31.761 23618 23642 I allegro : main     D 23642:               main.c:172  main                             [  12.30432] tick
11-06 09:13:31.928 23618 23642 E libEGL  : called unimplemented OpenGL ES API
11-06 09:13:32.762 23618 23642 I allegro : main     D 23642:               main.c:172  main                             [  13.30447] tick
11-06 09:13:32.929 23618 23642 E libEGL  : called unimplemented OpenGL ES API
11-06 09:13:33.772 23618 23642 I allegro : main     D 23642:               main.c:172  main                             [  14.31534] tick
11-06 09:13:33.932 23618 23642 E libEGL  : called unimplemented OpenGL ES API
11-06 09:13:34.761 23618 23642 I allegro : main     D 23642:               main.c:172  main                             [  15.30441] tick

SiegeLord

When you say that this is an issue with the Gradle repository binaries, do you mean that you compiled the newest master branch using the older instructions and it worked fine?

Polybios

Exactly. You can compare the logs I posted behind the two spoiler-buttons, although the one resulting from the gradle-build isn't as verbose.
Sorry if I haven't expressed this clearly enough.

Elias

Are you using the same manifest for both builds?

Polybios

No! After looking at the manifest file of the Android example, I think that's it. However, I don't have time to test this right now. Anyway, thank you!

I think it would be nice to make a note about that somewhere for unsuspecting/stupid people like me. :)

Elias

Yes, it should go to README_android.txt for sure. Basically if you don't set the "orientation" change in the manifest the application will not receive it.

Polybios

Unfortunately, my tests haven't produced different results so far: App still goes to background on changing orientation, even if I use the settings of the Android example's manifest in the gradle-built version. ???
Log output is the same (destroy instead of change config).

I think rebuilding it should suffice for the changes to take effect? What else could it be?

Elias

Can you post the manifest of the working and of the not working versions here? Maybe there still is some slight difference which could explain it?

What other difference is there between the two besides the manifests? Are any versions of any dependencies different maybe?

Polybios

Not working:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="nemo.allegrotest3">
    <uses-sdk android:minSdkVersion="10"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            android:launchMode="singleTask"
            android:screenOrientation="unspecified"
            android:configChanges="screenLayout|uiMode|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Working: (This is just allegro5/android/example/AndroidManifest.xml)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.liballeg.example"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="10"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
    <application android:label="@string/app_name" android:debuggable="true">
        <activity android:name="org.liballeg.example.ExampleActivity"
                  android:label="@string/app_name"
                  android:launchMode="singleTask"
                  android:screenOrientation="unspecified"
                  android:configChanges="screenLayout|uiMode|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

Edit: Dependencies: I've only compiled freetype myself for the working example, it was version 2.6.5. Besides, I don't know...
Edit2: I've just tried the debug version (thanks!), no difference, no more verbose log.
Edit3: Other differences: Well, for the working example, I've used Allegro5's build system and allegro5/android/example/run.sh to run it, after creating a native toolchain and compiling / installing freetype; the not working example is built with AndroidStudio following your instructions. That probably implies a lot of differences that I don't know much about.

Elias

This is what my game uses:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yellowdanger">
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
        android:label="Yellow &amp; Dangerous" android:supportsRtl="true">
        <activity
            android:screenOrientation="unspecified"
            android:configChanges="orientation|keyboardHidden|screenLayout|uiMode|screenSize"
            android:name=".YellowAndDangerous">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

But clearly the Manifest is not the problem since both your working and not working versions use basically the same one.

If you want you can post your not-working example and I can try and compile it here and see if I can spot any difference to what my game does.

Polybios

Well, it's just the Allegro5 Android example: allegro5/android/example/csrc/main.c

Edit: I've added my own asset directory to the project and copied alexlogo.png to it. That's the only one more thing I can think of.

Elias

Yes, I can reproduce it. And the fix is rather simple: Add "screenSize" to the configChanges in the manifest (yes, it was the manifest after all).

The reason is a bit more curious:

Quote:

Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must decalare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).

The precompiled .aar uses API level 15 (because it is the default in Android Studio), the Allegro instructions use API level 10. So that explains why in one case you need it and in the other you don't. Welcome to Android development! ;D

Polybios

Thanks a lot!!! :D

I've just been enjoying creating symlinks because the AS-monster managed to fill my /tmp with its gigabytes of updates. You could change the path in 2.1, but in 2.2 no more... So, yeah, I already love it. Thanks again!

Edit: Very nice, the original nullptr crash in my app has now disappeared, too.

Maybe you could be so kind as to add a note about the manifest to README_android.txt or the README.md at https://github.com/liballeg/android?

Elias

I updated the Allegro examples to include "screenSize" - that should prevent this particular problem in the future. It may make sense to lower the minimum SDK in the prebuilt binaries down to 10 as well (that was the real reason why you ran into the issue), but it's not high on my priority list. API 15 is ancient and a lot of things now require 15 or even 21.

With that I don't feel we need to mention in in README_android.txt at all... there is the big warning I quoted above in the Android documentation already and listing every Android peculiarity would require 100ds of pages :P

Polybios

Of course. Thanks again, I'm really relieved this finally got resolved!

One last question: I wonder whether there is a situation where you wouldn't want to receive these configuration changes (using Allegro5)?

Elias

I don't know for sure. My understanding is there is two ways to handle the orientation change - either create a new activity or handle the change within the activity. I always thought we use the former way and re-create the activity. Turns out I was wrong and the flags in the Manifest are precisely to tell Android that we do handle the changes which prevents it from destroying the activity.

It probably would be worthwhile also handling the other way in Allegro - I just added a github issue about it: https://github.com/liballeg/allegro5/issues/693

Thread #616556. Printed from Allegro.cc