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

App: Fix pausing without app instance #6404

Merged
merged 1 commit into from
Oct 5, 2020
Merged

App: Fix pausing without app instance #6404

merged 1 commit into from
Oct 5, 2020

Conversation

Fak3
Copy link
Contributor

@Fak3 Fak3 commented Jul 1, 2019

On android, pause event can come in early, before the app instance is
created.

fixes #6400

@matham
Copy link
Member

matham commented Jul 21, 2019

I'm not very familiar with how we handle pausing, but does App know how to deal with starting while it is paused? Because the previous code always terminated the app if it wasn't started yet, but with the changes the app will be able to start while it is paused.

@Fak3
Copy link
Contributor Author

Fak3 commented Jul 22, 2019

@matham I don't know much about it either, but it seems to me that when paused, the whole kivy app is stuck in this loop: https://github.com/Fak3/kivy/blob/074e14ed4b4a9b7dccf3d28996c47b875cd5b51a/kivy/core/window/window_sdl2.py#L485 so the app instance will not be created until it is unpaused.

@Sirfanas
Copy link

Having same issue, could you put your code as PEP8 so Travis stop fail ?
My App close itself sometimes for this reason...

@TechnoLenzer
Copy link

I have both an on_pause and on_resume function in my app class which work fine normally, so why is this issue still persisting? Should I basically restart everything (as in reschedule, reload screen, reset variables) within my on_resume function?

@matham
Copy link
Member

matham commented Aug 27, 2019

It'd also be nice to add a unit test for this - if you can.

@p3g4asus
Copy link

p3g4asus commented Oct 4, 2020

Thank you Fak3!!!!!!! This bug was driving me crazy. My app closed without any error and I did not have any Idea on how to fix. I applyed this patch and now it works. It is unreasonable to not have fixed this more than a year after this `patch.

--- a/kivy/core/window/window_sdl2.py	2020-08-06 15:43:26.000000000 +0200
+++ b/kivy/core/window/window_sdl2.py	2020-10-04 18:25:42.000000000 +0200
@@ -10,13 +10,13 @@
     - support scrolling
     - clean code
     - manage correctly all sdl events
 
 '''
 
-__all__ = ('WindowSDL', )
+__all__ = ('WindowSDL2', )
 
 from os.path import join
 import sys
 from kivy import kivy_data_dir
 from kivy.logger import Logger
 from kivy.base import EventLoop
@@ -226,17 +226,15 @@
             self.dispatch('on_memorywarning')
 
         elif action == 'app_willenterbackground':
             from kivy.base import stopTouchApp
             app = App.get_running_app()
             if not app:
-                Logger.info('WindowSDL: No running App found, exit.')
-                stopTouchApp()
-                return 0
+                Logger.info('WindowSDL: No running App found, pause.')
 
-            if not app.dispatch('on_pause'):
+            elif not app.dispatch('on_pause'):
                 Logger.info(
                     'WindowSDL: App doesn\'t support pause mode, stop.')
                 stopTouchApp()
                 return 0
 
             self._pause_loop = True
@@ -245,13 +243,14 @@
             # on iOS, the did enter foreground is launched at the start
             # of the application. in our case, we want it only when the app
             # is resumed
             if self._pause_loop:
                 self._pause_loop = False
                 app = App.get_running_app()
-                app.dispatch('on_resume')
+                if app:
+                    app.dispatch('on_resume')
 
         elif action == 'windowresized':
             self._size = largs
             self._win.resize_window(*self._size)
             # Force kivy to render the frame now, so that the canvas is drawn.
             EventLoop.idle()
@@ -704,17 +703,14 @@
     def do_pause(self):
         # should go to app pause mode (desktop style)
         from kivy.app import App
         from kivy.base import stopTouchApp
         app = App.get_running_app()
         if not app:
-            Logger.info('WindowSDL: No running App found, exit.')
-            stopTouchApp()
-            return
-
-        if not app.dispatch('on_pause'):
+            Logger.info('WindowSDL: No running App found, pause.')
+        elif not app.dispatch('on_pause'):
             Logger.info('WindowSDL: App doesn\'t support pause mode, stop.')
             stopTouchApp()
             return
 
         # XXX FIXME wait for sdl resume
         while True:
@@ -729,14 +725,15 @@
                 EventLoop.quit = True
                 break
             elif action == 'app_willenterforeground':
                 break
             elif action == 'windowrestored':
                 break
-
-        app.dispatch('on_resume')
+            
+        if app:
+            app.dispatch('on_resume')
 
     def _update_modifiers(self, mods=None, key=None):
         if mods is None and key is None:
             return
         modifiers = set()
 

Copy link

@p3g4asus p3g4asus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary because, otherwise, if the app on_pause gets called before the app is available (and this indeed CAN happen), when the app becomes available, it simply silently closes itself generating no error message.

Copy link
Member

@matham matham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for confirming this works

@matham matham merged commit 2b6441d into kivy:master Oct 5, 2020
@matham matham added this to the 2.0.0 milestone Oct 28, 2020
@matham matham changed the title fix pausing without app instance App: Fix pausing without app instance Dec 8, 2020
@matham matham added the Component: core-app app, clock, config, inspector, logger, resources, modules, clock, base.py label Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: core-app app, clock, config, inspector, logger, resources, modules, clock, base.py
Projects
None yet
Development

Successfully merging this pull request may close these issues.

android: [WindowSDL] No running App found, exit.
5 participants