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

Orientation change causes bogus SDL_QUIT and SDL_APP_TERMINATING events #1338

Closed
ghost opened this issue Aug 24, 2018 · 3 comments
Closed

Orientation change causes bogus SDL_QUIT and SDL_APP_TERMINATING events #1338

ghost opened this issue Aug 24, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 24, 2018

I am using PySDL2 + python-for-android without kivy. In my test app, the first orientation change seems to cause an SDL_QUIT and an SDL_APP_TERMINATING event, and I don't know why - it looks like a bug to me.

This is the test code (feel free to build & test for yourself, needs --requirements=sdl2,pysdl2,python3crystax, --orientation user of course, and possibly --window to reproduce):

#!/usr/bin/env python3

def apply_hack():
    import ctypes.util
    orig_func = ctypes.util.find_library
    def android_find_library_hack(*args):
        import os
        name = args[0]

        # Truncate ending for easier comparison:
        if name.find(".so.") >= 0:
            name = name.partition(".so.")[0]
        if name.endswith(".so"):
            name = name[:-len(".so")]
        if not name.endswith("."):
            name += "."

        # Helper function to check lib name:
        def check_name(lib_name, search_name):
            if filename.endswith('.so') and (
                    filename.startswith("lib" + search_name) or
                    filename.startswith(search_name)):
                return True
            if search_name.endswith("-2.0."):  # PySDL2 hack
                search_name = search_name[:-len("-2.0.")] + "."
                return check_name(lib_name, search_name)
            return False

        # Check the user app lib dir and system dir:
        app_root = os.path.normpath(os.path.abspath(os.path.join(
            os.path.dirname(__file__), '..', '..', 'lib')))
        sys_dir = "/system/lib"
        for lib_search in [app_root, sys_dir]:
            if not os.path.exists(lib_search):
                continue
            for filename in os.listdir(lib_search):
                if check_name(filename, name):
                    return os.path.join(lib_search, filename)
        return orig_func(*args)
    import ctypes.util
    ctypes.util.find_library = android_find_library_hack
apply_hack()

import ctypes
import sdl2 as sdl
import sys
import time
import traceback

window = None
renderer = None

def test_app():
    global window, renderer
    print("Creating window (app launch)...")
    sdl.SDL_Init(sdl.SDL_INIT_EVERYTHING)
    window = sdl.SDL_CreateWindow(
        "This is a test.".encode("utf-8", "replace"),
        sdl.SDL_WINDOWPOS_CENTERED, sdl.SDL_WINDOWPOS_CENTERED,
        640, 480, sdl.SDL_WINDOW_SHOWN |
        sdl.SDL_WINDOW_RESIZABLE)
    renderer = sdl.SDL_CreateRenderer(window, -1, 0)

    # Main event loop:
    while True:
        time.sleep(0.01)

        # Fetch events:
        events = []
        while True:
            ev = sdl.SDL_Event()
            result = sdl.SDL_PollEvent(ctypes.byref(ev))
            if result == 1:
                events.append(ev)
                continue
            break
        for event in events:
            handle_event(event)

def handle_event(event):
    global window, renderer

    if event.type == sdl.SDL_QUIT or \
            event.type == sdl.SDL_APP_TERMINATING:
        event_name = "SDL_QUIT"
        if event.type == sdl.SDL_APP_TERMINATING:
            event_name = "SDL_APP_TERMINATING"
        print("Terminating (app termination event: " +
            event_name + ").")
        print("Actually, ignoring this")
        #if renderer != None:
        #    sdl.SDL_DestroyRenderer(renderer)
        #    renderer = None
        #if window != None:
        #    sdl.SDL_DestroyWindow(window)
        #    window = None
        #sys.exit(0)
    elif event.type == sdl.SDL_WINDOWEVENT:
        if event.window.event == \
                sdl.SDL_WINDOWEVENT_CLOSE:
            # Throw away renderer:
            if renderer != None:
                sdl.SDL_DestroyRenderer(renderer)
                renderer = None
                print("Renderer destroyed (window closed).")
            # Close window:
            if window != None:
                sdl.SDL_DestroyWindow(window)
                window = None
                print("Window destroyed (window closed).")
                # Terminate if not on android:
                if sdl.SDL_GetPlatform().decode("utf-8").\
                        lower() != "android":
                    print("Terminating app since on desktop OS, " +
                        "and last window was closed.")
                    sys.exit(0)
        if (event.window.event ==
                sdl.SDL_WINDOWEVENT_RESTORED or
                event.window.event ==
                sdl.SDL_WINDOWEVENT_EXPOSED or
                event.window.event ==
                sdl.SDL_WINDOWEVENT_MAXIMIZED):
            # Re-create renderer if necessary:
            if renderer == None:
                print("Renderer re-created (got window focus).")
                renderer = sdl.SDL_CreateRenderer(window, -1, 0)
    elif (event.type == sdl.SDL_APP_DIDENTERBACKGROUND):
        print("Entered background.")
        # Wipe renderer:
        if renderer != None:
            sdl.SDL_DestroyRenderer(renderer)
            renderer = None
            print("Renderer destroyed (entered background).")
    elif (event.type == sdl.SDL_APP_WILLENTERFOREGROUND):
        print("Entering foreground.")
        # Re-create window if necessary:
        if window == None:
            window = sdl.SDL_CreateWindow(
                "This is a test.".encode("utf-8", "replace"),
                sdl.SDL_WINDOWPOS_CENTERED, sdl.SDL_WINDOWPOS_CENTERED,
                640, 480, sdl.SDL_WINDOW_SHOWN |
                sdl.SDL_WINDOW_RESIZABLE)
            if renderer != None:
                sdl.SDL_DestroyRenderer(renderer)
                renderer = None
                print("Renderer destroyed (new window).")
        # Re-create renderer if necessary:
        if renderer == None:
            renderer = sdl.SDL_CreateRenderer(window, -1, 0)
            print("Renderer re-created (entering foreground).")

test_app()

This is the output:

08-24 21:18:36.216  4475  4475 V SDL     : onResume()
08-24 21:18:36.218  4475  4491 V SDL     : asked to get string private_version
08-24 21:18:36.218  4475  4491 V SDL     : getting identifier
08-24 21:18:36.219  4475  4491 V SDL     : kind is string and name private_version
08-24 21:18:36.220  4475  4491 V SDL     : result is 2130968578
08-24 21:18:36.223  4475  4491 V PythonActivity: Data version is 1535137152.1970532
08-24 21:18:36.280  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libSDL2_mixer.so
08-24 21:18:36.280  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libSDL2_ttf.so
08-24 21:18:36.281  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libmain.so
08-24 21:18:36.281  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libSDL2.so
08-24 21:18:36.281  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libcrystax.so
08-24 21:18:36.281  4475  4475 V pythonutil: Pattern libcrystax\.so matched file libcrystax.so
08-24 21:18:36.281  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libSDL2_image.so
08-24 21:18:36.282  4475  4475 V pythonutil: Checking pattern libcrystax\.so against libpython3.5m.so
08-24 21:18:36.282  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_mixer.so
08-24 21:18:36.283  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_ttf.so
08-24 21:18:36.283  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libmain.so
08-24 21:18:36.283  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libSDL2.so
08-24 21:18:36.283  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libcrystax.so
08-24 21:18:36.283  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libSDL2_image.so
08-24 21:18:36.284  4475  4475 V pythonutil: Checking pattern libsqlite3\.so against libpython3.5m.so
08-24 21:18:36.284  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libSDL2_mixer.so
08-24 21:18:36.285  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libSDL2_ttf.so
08-24 21:18:36.285  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libmain.so
08-24 21:18:36.285  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libSDL2.so
08-24 21:18:36.285  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libcrystax.so
08-24 21:18:36.285  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libSDL2_image.so
08-24 21:18:36.286  4475  4475 V pythonutil: Checking pattern libssl.*\.so against libpython3.5m.so
08-24 21:18:36.286  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_mixer.so
08-24 21:18:36.287  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_ttf.so
08-24 21:18:36.287  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libmain.so
08-24 21:18:36.287  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2.so
08-24 21:18:36.287  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libcrystax.so
08-24 21:18:36.287  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libSDL2_image.so
08-24 21:18:36.288  4475  4475 V pythonutil: Checking pattern libcrypto.*\.so against libpython3.5m.so
08-24 21:18:36.288  4475  4475 V pythonutil: Loading library: crystax
08-24 21:18:36.293  4475  4475 V pythonutil: Loading library: SDL2
08-24 21:18:36.297  4475  4475 V pythonutil: Loading library: SDL2_image
08-24 21:18:36.299  4475  4475 V pythonutil: Loading library: SDL2_mixer
08-24 21:18:36.302  4475  4475 V pythonutil: Loading library: SDL2_ttf
08-24 21:18:36.303  4475  4475 V pythonutil: Loading library: python2.7
08-24 21:18:36.311  4475  4475 V pythonutil: Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/app/org.example.myapp-1/base.apk"],nativeLibraryDirectories=[/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/app/org.example.myapp-1/lib/arm, /system/fake-libs, /mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/app/org.example.myapp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]] couldn't find "libpython2.7.so"
08-24 21:18:36.312  4475  4475 V pythonutil: Loading library: python3.5m
08-24 21:18:36.317  4475  4475 V pythonutil: Loading library: main
08-24 21:18:36.319  4475  4475 V pythonutil: Failed to load _io.so or unicodedata.so...but that's okay.
08-24 21:18:36.320  4475  4475 V pythonutil: Unsatisfied linker when loading ctypes
08-24 21:18:36.320  4475  4475 V pythonutil: Loaded everything!
08-24 21:18:36.351  4475  4475 V PythonActivity: Setting env vars for start.c and Python to use
08-24 21:18:36.351  4475  4475 V PythonActivity: Access to our meta-data...
08-24 21:18:36.353  4475  4475 I PythonActivity: Surface will NOT be transparent
08-24 21:18:36.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:36.366  4475  4492 I Adreno-EGL: <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 10/21/15, 369a2ea, I96aee987eb
08-24 21:18:36.373  4475  4492 I OpenGLRenderer: Initialized EGL, version 1.4
08-24 21:18:36.373  4475  4492 D OpenGLRenderer: Swap behavior 1
08-24 21:18:36.398  4475  4475 V SDL     : surfaceCreated()
08-24 21:18:36.398  4475  4475 V SDL     : surfaceChanged()
08-24 21:18:36.398  4475  4475 V SDL     : pixel format RGB_565
08-24 21:18:36.400  4475  4475 V SDL     : Window size:540x924
08-24 21:18:36.420  1845  5302 D Sensors : setDelay: acc_delay=20000000, mag_delay=200000000
08-24 21:18:36.420  1845  5302 D Sensors : setDelay: handle=0, delay=20000000
08-24 21:18:36.451  4475  4494 I SDL     : SDL_Android_Init()
08-24 21:18:36.452  4475  4494 I SDL     : SDL_Android_Init() finished!
08-24 21:18:36.452  4475  4494 I python  : Initialize Python for Android
08-24 21:18:36.452  4475  4494 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
08-24 21:18:36.452  4475  4494 I python  : /mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app
08-24 21:18:36.452  4475  4494 I python  : Preparing to initialize python
08-24 21:18:36.471  4475  4494 I python  : crystax_python exists
08-24 21:18:36.471  4475  4494 I python  : calculated paths to be...
08-24 21:18:36.471  4475  4494 I python  : /mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app/crystax_python/stdlib.zip:/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app/crystax_python/modules
08-24 21:18:36.472  4475  4494 I python  : set wchar paths...
08-24 21:18:36.527  4475  4475 V SDL     : onWindowFocusChanged(): true
08-24 21:18:36.535  1845  1866 I ActivityManager: Displayed org.example.myapp/org.kivy.android.PythonActivity: +563ms
08-24 21:18:36.849  1480  1518 I ThermalDaemon: Sensor 'tsens_tz_sensor0' - alarm raised 1 at 50.0 degC
08-24 21:18:37.361  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:37.547  4475  4494 I python  : Initialized python
08-24 21:18:37.547  4475  4494 I python  : AND: Init threads
08-24 21:18:37.549  4475  4494 I python  : testing python print redirection
08-24 21:18:37.554  4475  4494 I python  : Android path ['.', '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app/crystax_python/stdlib.zip', '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app/crystax_python/modules', '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app/crystax_python/site-packages']
08-24 21:18:37.556  4475  4494 I python  : os.environ is environ({'ASEC_MOUNTPOINT': '/mnt/asec', 'ANDROID_SOCKET_zygote': '9', 'LD_PRELOAD': 'libsigchain.so', 'ANDROID_STORAGE': '/storage', 'ANDROID_ASSETS': '/system/app', 'BOOTCLASSPATH': '/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/apache-xml.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/telephony-ext.jar', 'ANDROID_BOOTLOGO': '1', 'PYTHONHOME': '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app', 'PYTHONPATH': '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app:/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app/lib', 'ANDROID_UNPACK': '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app', 'LD_SHIM_LIBS': '/system/lib/libril.so|libshim_ril.so:/system/bin/mm-qcamera-daemon|libshim_camera.so', 'ANDROID_CACHE': '/cache', 'ANDROID_ROOT': '/system', 'SYSTEMSERVERCLASSPATH': '/system/framework/org.cyanogenmod.platform.jar:/system/framework/org.cyanogenmod.hardware.jar:/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar', 'TERMINFO': '/system/etc/terminfo', 'PYTHON_NAME': 'python', 'ANDROID_PRIVATE': '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files', 'ANDROID_ARGUMENT': '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app', 'EXTERNAL_STORAGE': '/sdcard', 'DOWNLOAD_CACHE': '/cache', 'PATH': '/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin', 'PYTHONOPTIMIZE': '2', 'ANDROID_APP_PATH': '/mnt/expand/ccbe4e94-5878-4053-8382-d825486cc844/user/0/org.example.myapp/files/app', 'ANDROID_ENTRYPOINT': 'main.pyo', 'ANDROID_DATA': '/data'})
08-24 21:18:37.558  4475  4494 I python  : Android kivy bootstrap done. __name__ is __main__
08-24 21:18:37.558  4475  4494 I python  : AND: Ran string
08-24 21:18:37.558  4475  4494 I python  : Run user program, change dir and execute entrypoint
08-24 21:18:37.558  4475  4494 I python  : main.py
08-24 21:18:38.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:39.361  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:39.823 10771 10771 D GeckoMemoryMonitor: onTrimMemory() notification received with level 80
08-24 21:18:40.091  4475  4494 I python  : Creating window (app launch)...
08-24 21:18:40.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:41.000  1480  1518 I ThermalDaemon: Sensor 'tsens_tz_sensor0' - alarm cleared 1 at 46.0 degC
08-24 21:18:41.363  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:42.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:43.365  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:44.363  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:45.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:46.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:47.363  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:48.046  1845  1860 I ActivityManager: Config changes=480 {1.0 262mcc7mnc [en_US] ldltr sw360dp w640dp h336dp 240dpi nrml long land finger -keyb/v/h -nav/h s.48}
08-24 21:18:48.078  1845  1904 I InputReader: Reconfiguring input devices.  changes=0x00000004
08-24 21:18:48.078  1845  1904 I InputReader: Device reconfigured: id=11, name='sec_touchscreen', size 540x960, orientation 3, mode 1, display id 0
08-24 21:18:48.083  1845  1904 I InputReader: Reconfiguring input devices.  changes=0x00000004
08-24 21:18:48.147 10771 10771 D GeckoApplication: onConfigurationChanged: en_US, background: true
08-24 21:18:48.280  4475  4475 V PythonActivity: onPause()
08-24 21:18:48.280  4475  4475 V SDL     : onPause()
08-24 21:18:48.280  4475  4475 V SDL     : nativePause()
08-24 21:18:48.280  4475  4475 E libEGL  : call to OpenGL ES API with no current context (logged once per thread)
08-24 21:18:48.281  1845  5577 D Sensors : setDelay: acc_delay=66667000, mag_delay=200000000
08-24 21:18:48.281  1845  5577 D Sensors : setDelay: handle=0, delay=66667000
08-24 21:18:48.284  4475  4494 I python  : Entered background.
08-24 21:18:48.287  4475  4475 V SDL     : onDestroy()
08-24 21:18:48.297  4475  4494 I python  : Renderer destroyed (entered background).
08-24 21:18:48.308  4475  4494 I python  : Terminating (app termination event: SDL_QUIT).
08-24 21:18:48.308  4475  4494 I python  : Actually, ignoring this
08-24 21:18:48.308  4475  4494 I python  : Terminating (app termination event: SDL_APP_TERMINATING).
08-24 21:18:48.308  4475  4494 I python  : Actually, ignoring this
08-24 21:18:48.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:49.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:49.980  1845  1866 W WindowManager: Window freeze timeout expired.
08-24 21:18:49.981  1845  1866 W WindowManager: Force clearing orientation change: Window{3a2c612 u0 org.example.myapp/org.kivy.android.PythonActivity}
08-24 21:18:49.981  1845  1866 W WindowManager: Force clearing orientation change: Window{971fcdc u0 com.android.systemui.ImageWallpaper}
08-24 21:18:50.274  1845  1866 W WindowManager: App freeze timeout expired.
08-24 21:18:50.274  1845  1866 W WindowManager: Force clearing freeze: AppWindowToken{c4f40ae token=Token{d6cb2b0 ActivityRecord{191b5f3 u0 org.example.myapp/org.kivy.android.PythonActivity t3386}}}
08-24 21:18:50.281  1845  1866 I WindowManager: Screen frozen for +2s302ms due to Window{3a2c612 u0 org.example.myapp/org.kivy.android.PythonActivity}
08-24 21:18:50.366  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:51.363  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:52.314  1845  1866 I art     : Starting a blocking GC Explicit
08-24 21:18:52.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:52.480  1845  1866 I art     : Explicit concurrent mark sweep GC freed 52461(2MB) AllocSpace objects, 5(116KB) LOS objects, 33% free, 11MB/17MB, paused 2.319ms total 157.057ms
08-24 21:18:53.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:54.364  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:55.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:56.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:57.363  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:58.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:18:59.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:00.361  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:01.365  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:01.544  1845  1904 I InputReader: Reconfiguring input devices.  changes=0x00000004
08-24 21:19:01.544  1845  1904 I InputReader: Device reconfigured: id=11, name='sec_touchscreen', size 540x960, orientation 0, mode 1, display id 0
08-24 21:19:01.548  1845  1904 I InputReader: Reconfiguring input devices.  changes=0x00000004
08-24 21:19:01.553  1845  1860 I ActivityManager: Config changes=480 {1.0 262mcc7mnc [en_US] ldltr sw360dp w360dp h616dp 240dpi nrml long port finger -keyb/v/h -nav/h s.49}
08-24 21:19:01.607 10771 10771 D GeckoApplication: onConfigurationChanged: en_US, background: true
08-24 21:19:02.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:03.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:03.465  1845  1866 W WindowManager: Window freeze timeout expired.
08-24 21:19:03.465  1845  1866 W WindowManager: Force clearing orientation change: Window{3a2c612 u0 org.example.myapp/org.kivy.android.PythonActivity}
08-24 21:19:03.465  1845  1866 W WindowManager: Force clearing orientation change: Window{971fcdc u0 com.android.systemui.ImageWallpaper}
08-24 21:19:03.665  1845  1866 W WindowManager: App freeze timeout expired.
08-24 21:19:03.666  1845  1866 W WindowManager: Force clearing freeze: AppWindowToken{c4f40ae token=Token{d6cb2b0 ActivityRecord{191b5f3 u0 org.example.myapp/org.kivy.android.PythonActivity t3386}}}
08-24 21:19:03.675  1845  1866 I WindowManager: Screen frozen for +2s212ms due to Window{3a2c612 u0 org.example.myapp/org.kivy.android.PythonActivity}
08-24 21:19:04.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:05.362  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0
08-24 21:19:05.719  1845  1866 I art     : Starting a blocking GC Explicit
08-24 21:19:05.868  1845  1866 I art     : Explicit concurrent mark sweep GC freed 5273(239KB) AllocSpace objects, 0(0B) LOS objects, 33% free, 11MB/17MB, paused 2.380ms total 145.978ms
08-24 21:19:06.365  1845  1881 D Sensors : LightSensor readEvents x = 0.000000, raw = 0

All I did during this output was 1. launch the app, 2. change screen orientation.
This is the output indicating the bug:

08-24 21:18:48.308  4475  4494 I python  : Terminating (app termination event: SDL_QUIT).
08-24 21:18:48.308  4475  4494 I python  : Actually, ignoring this
08-24 21:18:48.308  4475  4494 I python  : Terminating (app termination event: SDL_APP_TERMINATING).
08-24 21:18:48.308  4475  4494 I python  : Actually, ignoring this

This simply shouldn't happen, I think. I'm not sure why it does. When I change the code to not ignore those bogus events and actually terminate, the app crashes on orientation change with some java wrapper backtrace that looks like it's confused why the SDL window is suddenly gone. (well, why did it send me SDL_QUIT and SDL_APP_TERMINATING then...?)

Also, even more strangely, for any later orientation changes, this no longer happens. The bogus events only get sent for the very first one right after the app launched into my main.py code.

Steps to reproduce:

  1. Build code above with --requirements=python3crystax,pysdl2,sdl2 --orientation user --window (last flag may or may not be required to reproduce)
  2. Launch app, don't rotate the phone while it still unpacks & loads
  3. When screen goes black and after adb logcat confirmed the app launch with the line Creating window (app launch)..., rotate your phone
  4. Observe bogus events in log (or change the commented out code to be active, and observe the crash)
@ghost
Copy link
Author

ghost commented Aug 24, 2018

Interestingly, kivy doesn't seem to have special handling for SDL_QUIT that somehow works around this: https://github.com/kivy/kivy/blob/96dfa5b55ed74c8223152dd84cd478bfed03e90b/kivy/core/window/_window_sdl2.pyx#L521

Am I doing something unusual again that could cause this? Do all kivy apps just terminate on screen rotation? 😕 Weird

@ghost
Copy link
Author

ghost commented Aug 25, 2018

-- snip - what i wrote here may have been just confusion on my side, I'm still investigating --

@ghost
Copy link
Author

ghost commented Aug 26, 2018

closing since I finally managed to debug p4a to find out what the issue is

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants