Proper way to exit game (SOLVED)


#1

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.


#2

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


#3

Thank you! That worked perfectly :slight_smile:


#4

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 msg.post("@system:", “exit”, {code = 0}):

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

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


#5

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?


#6

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?


#7

Which extensions do you use?

Yes, this could perhaps be a reason.


#8

2018-05-23_21-08-03
+share


#9

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: https://github.com/AGulev/DefUnityAds/blob/master/defunityads/src/DefUnityCallback.cpp#L8-L18

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


#10

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.


#11

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.