-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Conversation
I'm not very familiar with how we handle pausing, but does |
@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. |
Having same issue, could you put your code as PEP8 so Travis stop fail ? |
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? |
It'd also be nice to add a unit test for this - if you can. |
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()
|
There was a problem hiding this 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.
There was a problem hiding this 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
On android, pause event can come in early, before the app instance is
created.
fixes #6400