How to close kivent app on pause or on stop

65 views
Skip to first unread message

Zain ul Abedeen

unread,
Oct 11, 2018, 7:22:38 AM10/11/18
to KivEnt
What is the correct way to stop a kivent app if a user a switches the running app or press home button on screen.
I've tried the following but none works. The loaded entities and systems appear to be in the memory and causes memory leak

class Project(App):

    def build(self):
        Window.clearcolor = (0, 0, 0, 1.)


---------------------------------------------------
class Project(App):

    def stop(self):
        return True

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

class Project(App):

    def on_pause(self):
        sys.exit(0)

        return True
    def on_resume(self):
        pass


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

class Project(App):

    def on_pause(self):
        App.get.running.app().stop()

        return True
    def on_resume(self):
        pass

Thanks!

Łukasz Mach

unread,
Oct 12, 2018, 11:42:47 AM10/12/18
to kivent@googlegroups.com >> KivEnt
W dniu 11.10.2018 o 13:22, Zain ul Abedeen pisze:
> What is the correct way to stop a kivent app if a user a switches the
> running app or press home button on screen.
> I've tried the following but none works. The loaded entities and systems
> appear to be in the memory and causes memory leak
>
[...]

>
> class Project(App):
>
>     def on_pause(self):
>         sys.exit(0)
>
>         return True
>     def on_resume(self):
>         pass
>

What happends after sys.exit ? Process still hangs out not killed?

regards

Maho
Message has been deleted

Zain ul Abedeen

unread,
Oct 12, 2018, 5:25:11 PM10/12/18
to KivEnt
I get this error:

I/python  (10441):  Exception SystemExit: 0 in 'kivy.core.window._window_sdl2._WindowSDL2Storage.cb_event_filter' ignored

and the app breaks and becomes unresponsive

Jacob Kovac

unread,
Oct 12, 2018, 8:52:34 PM10/12/18
to zain ul abedeen, KivEnt
You should not be calling sys.exit, app has a stop command if you want to stop the app.


In general to properly do a pause/restart you should be clearing every entity, and getting rid of your gameworld. You would then instantiate a whole new gameworld the same as starting up the app for the first time. Theoretically if you just let your Gameworld get garbage collected everything should clean up properly. However, it might be nice to extend GameWorld to have an explicit deallocate function. This is not implemented at this time. It should be sufficient to just clear the GameWorld's master_buffer as every other system allocates from there. You should definitely be removing all entities and probably all systems. The thing about pause on android is you should never count on unpause happening as the OS could choose to cleanup your app. Pausing should be the exact same behavior as stopping the app entirely and restarting, any thing you want to persist needs to be serialized and deserialized.

--
You received this message because you are subscribed to the Google Groups "KivEnt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivent+un...@googlegroups.com.
To post to this group, send email to kiv...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivent/32f215c9-ad2d-497a-b542-85f137a033e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zain ul Abedeen

unread,
Oct 13, 2018, 5:39:25 PM10/13/18
to KivEnt

- How to delete Gameworld, or its master_buffer? (could'nt call self.gameworld.memory_handlers.membuffer.Buffer)

- How to restore Gamworld?


I have elaborated by question in this gist, https://gist.github.com/thegameguy/7d3cf9b27e6dd5915a8b80e1de25e620

Regards

Zain ul Abedeen

unread,
Oct 13, 2018, 9:41:34 PM10/13/18
to KivEnt

ok, so its self.gameworld.master_buffer, assuming it gets cleared if its master_buffer = None, 

now if self.gameworld.init(list_of_systems, callback = init_game) is called, it gives the error below

   File "kivent_core\gameworld.pyx", line 271, in kivent_core.gameworld.GameWorld.init_gameworld (kivent_core/gameworld.c:6012)
   File "kivent_core\gameworld.pyx", line 197, in kivent_core.gameworld.GameWorld.ensure_startup (kivent_core/gameworld.c:4592)
 TypeError: 'NoneType' object is not iterable

if i call del self.gameworld before gameworld.init call, I get the following error,

     del self.gameworld
 NotImplementedError: __delete__
 

Zain ul Abedeen

unread,
Oct 14, 2018, 10:07:06 AM10/14/18
to KivEnt

if I do self.gameworld = None, i get

ValueError: None is not allowed for TestGame.gameworld

There is not much info about how to manually gc Gameworld. del and None are not working to get rid of the gameworld.


Jacob Kovac

unread,
Oct 15, 2018, 1:00:54 PM10/15/18
to zain ul abedeen, KivEnt
It looks like I made a mistake on the implementation here and we actually do need to manually implement delete on the GameWorld.

Would you mind opening a github issue about this?

--
You received this message because you are subscribed to the Google Groups "KivEnt" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivent+un...@googlegroups.com.
To post to this group, send email to kiv...@googlegroups.com.

Zain ul Abedeen

unread,
Oct 15, 2018, 9:18:40 PM10/15/18
to KivEnt
This game engine has so much love in it. I really hope it becomes capable of restarting the game on pause/resume soon.


Regards

Zain ul Abedeen

unread,
Nov 12, 2018, 6:53:12 AM11/12/18
to KivEnt
Hey, sorry my bad, on_pause if all running systems are paused and un-paused on_resume function the app has no problems. There is one tiny trick that is to setup a new state which has a list of currently running systems and call this state 'resume'. This state should be setup during on_pause method similar to setting up states at the beginning in the init_game call. and on_resume this state should be set so the currently running systems get un_paused. if the user leaves your app in background for too long than the screen may be blank. Also it is good to call the restore function with a delay of 0.1 in a Clock.schedule_once(self.restore, 0.1).

Check my Gloworld app as a running example. 

Regards

proze...@gmail.com

unread,
Nov 15, 2018, 3:54:25 AM11/15/18
to KivEnt
I have tested for hours but the app won't go blank with these settings. Have not been able to reproduce the blank screen error!
Reply all
Reply to author
Forward
0 new messages