Proper way to exit game (SOLVED)


Is there a specific way to exit a Defold application entirely?

I’m currently using os.exit() which works on desktop and Android but generates a “Unfortunately, program has stopped responding” message on the latter.


We have an exit message, which hopefully should help in this case. :slight_smile:


Thank you! That worked perfectly :slight_smile:


Again about exit from the Android game.
Sometimes I’ve got the report from users like this one:

Sometimes the game freeze if you try to close it with the back button. Then you have to close it with the task manager. Otherwise no bugs found. Samsung Galaxy S6 SM-G920F, Android 7.0

In my code I have listen key-back and than call"@system:", “exit”, {code = 0}):

elseif action_id==game.BACK and action.released then
		if 	game.currentscene==game.MAINMENU then
			print("Time to exit!")"@system:", "exit", {code = 0})

Usually all work correct, but users reports…
What can be wrong?


That snippet of code looks good. Could it be that the finish() function of a script goes into an infinite loop? Or could it be that one of the native extensions goes into an infinite loop in the finish callback?


Great question! In final() i haven’t do any loop. Extension… good point, but how to catch who is this bandit. Also it may be unwanted callback from asynchronous code like playfab http response?


Which extensions do you use?

Yes, this could perhaps be a reason.




Google Analytics and PlayFabClientSdk are pure Lua extensions and as far as I know none of them have any code that is expected to run when the application shuts down.

Defold-Timer does nothing in the finalize stage of the extension (although I realise now that I need to do some cleanup just to be sure, although unrelated to your issue).

DefUnityAds does run some code in finalize:

DefReview does nothing in finalize. The same for defold-sharing.


I’ll remove this method in next DefUnityAds update (~in hour)
This method have no sense because of really rare cases when it’s useful - only for developers with big “luck” who use dmengine.
But I think it’s not a reason of the problem.


No, probably not.

@Dragosha: Pushed a new version (1.1.2) of Defold-timer. Please update as this release fixes a crash when doing Build and having an instance of the app already running.