Crash when app comes back from sleep

#1

This crash happens consistently on iPhone XR, after the device is reactivated after going to sleep:

ERROR:SCRIPT: rendercam/rendercam.render_script:38: argument #1 contains one or more values which are not numbers: vmath.matrix4(nan, 0, 0, nan, 0, nan, 0, nan, 0, 0, -1, -0, 0, 0, 0, 1)
stack traceback:
	[C]: in function 'set_projection'
	rendercam/rendercam.render_script:38: in function <rendercam/rendercam.render_script:30>

It might be that iOS stop sending the app data after it’s gone to sleep? @ross.grams, any idea?

1 Like

Monarch, Rendercam, and GUI Problems
Weird error from orthographic camera (SOLVED)
#2

I think it might be related to this

It’s scheduled for 1.2.171 currently

(Love the public github projects)

3 Likes

#3

Similar:


Slasher-prototype uses perspective cam too.
Other my game “LyL” does not use Rendercam, but also works in perspective mode and has the same issue.
I saw other Defold games on this iPad and they haven’t this issue :thinking:

3 Likes

#4

Hmm, that’s a pain. It seems like the engine must be giving some really weird values somewhere. Hmm…oh, I think if it gives the window width/height as 0, 0 that would create a NaN value in Rendercam. I could possibly add a check for that.

This is only in iOS, not Android?
Does it work with an orthographic camera?
If you set a window event listener, what data does it give you?

0 Likes

#5

We did a fix recently (1.2.169, https://github.com/defold/defold/issues/3712) where we check vector3, vector4 and matrix for invalid values (inf and nan). This fix was added to solve problems with for instance physics when passing in invalid values for rotation which resulted in a hard crash.

The fix we’ve made this release (references by @gianmichele above) is for when you use the new “Run While Iconified” option on Windows. While the game is iconified the window width and height gets reported as 0 which results in inf values in the projection. We will no longer call the render script while the game is iconified.

1 Like

#6

So this is probably a new isue? This is the version I’m using:

0 Likes

#7

Yeah, only iOS.

I had a custom renderscript which had this error, then switched to Rendercam because, you know, aaawesome. I haven’t tested with Orthographic, but likely it has the same issue.

0 Likes

#8

Can you please log what render.get_window_width() etc return when the error happens? I’m guessing Defold/the OS reports 0 or something similar when returning the app from the background.

0 Likes

#9

Sure! I modified Rendercam’s renderscript to print all values it gets from render. This means the line number of the error is no longer accurate. Please see the first message for a line number that correlates with Rendercam v1.0.2.

The last print before the error:

default	14:00:44.821013+0100	MyGame	DEBUG:SCRIPT: rendercam.update()	RenderScript: 0x01102df0d0
default	14:00:44.821070+0100	MyGame	DEBUG:SCRIPT: 	render.get_width()	1124
default	14:00:44.821126+0100	MyGame	DEBUG:SCRIPT: 	render.get_height()	2436
default	14:00:44.821182+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	750
default	14:00:44.821630+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	1624
default	14:00:45.816994+0100	MyGame	0x1122ddbd0 - ApplicationStateTracker: UISceneDidEnterBackground
default	14:00:45.817811+0100	MyGame	0x106101e18 - [pageProxyID=6, webPageID=7, PID=383] WebPageProxy::applicationDidEnterBackground: isSuspendedUnderLock? 1
default	14:00:45.818109+0100	MyGame	0x1122dfe80 - ApplicationStateTracker: UISceneDidEnterBackground
default	14:00:45.818252+0100	MyGame	0x1122decb0 - ApplicationStateTracker: UISceneDidEnterBackground
default	14:00:45.818366+0100	MyGame	0x10612c618 - [pageProxyID=22, webPageID=23, PID=388] WebPageProxy::applicationDidEnterBackground: isSuspendedUnderLock? 1
default	14:00:45.818567+0100	MyGame	0x1127d04b0 - ApplicationStateTracker: UISceneDidEnterBackground
default	14:00:45.819294+0100	MyGame	0x10612ea18 - [pageProxyID=28, webPageID=29, PID=389] WebPageProxy::applicationDidEnterBackground: isSuspendedUnderLock? 1

The error:

default	14:01:24.008550+0100	MyGame	DEBUG:SCRIPT: rendercam.update_window()	RenderScript: 0x01102df0d0
default	14:01:24.008651+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	0
default	14:01:24.008759+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	0
default	14:01:24.008815+0100	MyGame	DEBUG:SCRIPT: 	rendercam.window.x	750
default	14:01:24.008867+0100	MyGame	DEBUG:SCRIPT: 	rendercam.window.y	1624
default	14:01:24.008920+0100	MyGame	DEBUG:SCRIPT: 	rendercam.update_window()	0	0
default	14:01:24.008972+0100	MyGame	DEBUG:SCRIPT: 	vmath.matrix4_orthographic()	0	0	0	0	-1	1
default	14:01:24.009027+0100	MyGame	DEBUG:SCRIPT: rendercam.update_window()	RenderScript: 0x01102df0d0
default	14:01:24.009079+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	0
default	14:01:24.009135+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	0
default	14:01:24.009190+0100	MyGame	DEBUG:SCRIPT: 	rendercam.window.x	0
default	14:01:24.009243+0100	MyGame	DEBUG:SCRIPT: 	rendercam.window.y	0
default	14:01:24.009298+0100	MyGame	DEBUG:SCRIPT: 	rendercam.update_window()	0	0
default	14:01:24.009351+0100	MyGame	DEBUG:SCRIPT: 	vmath.matrix4_orthographic()	0	0	0	0	-1	1
default	14:01:24.009406+0100	MyGame	DEBUG:SCRIPT: rendercam.update()	RenderScript: 0x01102df0d0
default	14:01:24.009524+0100	MyGame	DEBUG:SCRIPT: 	render.get_width()	1124
default	14:01:24.009666+0100	MyGame	DEBUG:SCRIPT: 	render.get_height()	2436
default	14:01:24.009728+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	0
default	14:01:24.009780+0100	MyGame	DEBUG:SCRIPT: 	render.get_window_width()	0
default	14:01:24.010005+0100	MyGame	ERROR:SCRIPT: custom/rendercam.render_script:61: argument #1 contains one or more values which are not numbers: vmath.matrix4(nan, 0, 0, nan, 0, nan, 0, nan, 0, 0, -1, -0, 0, 0, 0, 1)
stack traceback:
	[C]: in function 'set_projection'
	custom/rendercam.render_script:61: in function <custom/rendercam.render_script:46>
default	14:01:24.010180+0100	MyGame	ERROR:GRAPHICS: OpenGLClear(1108): gl error 1286
default	14:01:24.012115+0100	MyGame	Resetting scope = 1, element = 0

It looks like you’re right! What’s the next step?

1 Like

#10

Does this also happen with the default render script?

0 Likes

#11

You could try this Rendercam version: https://github.com/rgrams/rendercam/archive/ios_iconified.zip I just set it to skip updating the camera stuff if the window width/height are 0, 0. Unfortunately I don’t have an iOS device to test it on.

I’m guessing it’s only a problem with perspective cameras, and possibly fixed aspect ratio cameras, since with a width/height of 0, 0, the aspect ratio becomes NaN.

1 Like

#12

The iOS devices I have also don’t have this issue, regrettably. I’m trying to get a crash with an iPhone XR on the Xcode Simulator. I’ll report back.

2 Likes

#13

I wasn’t able to get a crash with the Simulator, even though I was using the exact same iPhone image (iPhone XR). It isn’t possible to simulate the device going to sleep with the simulator, which leads me to believe the crash is directly related to that.

Yes! I built a completely blank project, with no extensions, and after coming back to life it crashed with the error below. The only change to the project was adding prints to the built in render script. It appears Rendercam is out of the loop.

default	11:07:14.644812+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT: default.update.init()	RenderScript: 0x010d585610
default	11:07:14.644870+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_width()	750
default	11:07:14.644927+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_height()	1624
default	11:07:14.644984+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_width()	1124
default	11:07:14.645040+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_height()	2436
default	11:07:14.645096+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT: default.render_script.get_projection()	RenderScript: 0x010d585610
default	11:07:14.645152+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_width()	750
default	11:07:14.645207+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_height()	1624
default	11:07:14.645265+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_width()	1124
default	11:07:14.645319+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_height()	2436
default	11:07:14.645375+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT: default.render_script.stretch_projection()	-1	1
default	11:07:14.645431+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_width()	750
default	11:07:14.647609+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_height()	1624
default	11:07:14.648149+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_width()	1124
default	11:07:14.648318+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_height()	2436
default	11:07:15.734287+0100	MyGameTestingSleepCrash	failed to make complete framebuffer object 8cd6
default	11:07:16.837642+0100	MyGameTestingSleepCrash	failed to make complete framebuffer object 8cd6
default	11:07:32.588996+0100	MyGameTestingSleepCrash	HTHangEventCreate: HangTracing is disabled. Not creating a new event.
default	11:07:32.589533+0100	MyGameTestingSleepCrash	Call host has no calls
default	11:07:32.600483+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT: default.update.init()	RenderScript: 0x010d585610
default	11:07:32.600563+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_width()	0
default	11:07:32.600622+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_height()	0
default	11:07:32.600681+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_width()	1124
default	11:07:32.600824+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_height()	2436
default	11:07:32.601157+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT: default.render_script.get_projection()	RenderScript: 0x010d585610
default	11:07:32.601223+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_width()	0
default	11:07:32.601413+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_height()	0
default	11:07:32.601612+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_width()	1124
default	11:07:32.601974+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_height()	2436
default	11:07:32.602061+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT: default.render_script.stretch_projection()	-1	1
default	11:07:32.602121+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_width()	0
default	11:07:32.602206+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_window_height()	0
default	11:07:32.602272+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_width()	1124
default	11:07:32.602340+0100	MyGameTestingSleepCrash	DEBUG:SCRIPT:     render.get_height()	2436
default	11:07:32.602396+0100	MyGameTestingSleepCrash	ERROR:SCRIPT: custom/default.render_script:125: argument #1 contains one or more values which are not numbers: vmath.matrix4(inf, 0, 0, nan, 0, inf, 0, nan, 0, 0, -1, -0, 0, 0, 0, 1)
stack traceback:
	[C]: in function ‘set_projection’
	custom/default.render_script:125: in function <custom/default.render_script:94>
default	11:07:32.602843+0100	MyGameTestingSleepCrash	ERROR:GRAPHICS: OpenGLClear(1108): gl error 1286
default	11:07:32.605648+0100	MyGameTestingSleepCrash	INFO:CRASH: Successfully wrote Crashdump to file: /var/mobile/Containers/Data/Application/4DE1C419-65B0-4C57-98B0-18C2EC3BEDC6/Library/Application Support/Defold/_crash

This issue is holding up the iOS release of one of my games. Any idea of how to fix or mitigate it?

1 Like

#14

Yes, the problem is that the window width/height is reported as 0 and that results in an invalid project matrix:

render.set_projection(vmath.matrix4_orthographic(0, render.get_window_width(), 0, render.get_window_height(), -1, 1))

Values will be nan (not a number) in the case of window width/height being 0. Quick fix is to check for this and not render anyting:

function update(self)
    local ww = render.get_window_width()
    local wh = render.get_window_height()
    if ww == 0 or wh == 0 then
        return
    end
0 Likes

#15

I will look into this and see what we can do to prevent it.

0 Likes

#16

I have tested this on a new build. The crash still happens, but there is no Lua error this time. See below.

I believe this is the fix @ross.grams added above, and although the Lua error is fixed, the crash still happens. This is the log with Rendercam ignoring 0 values: log.txt (565.6 KB)

Edit: Could it be this line that’s causing the crash?

default	13:06:38.908632+0100	MyGame	ERROR:GRAPHICS: OpenGLClear(1108): gl error 1286
0 Likes

#17

Is it an actual crash out of the application or a logged error? I don’t see an actual callstack or other indication of a proper hard crash.

0 Likes

#18

Yes, the app closes down. When restarted it doesn’t resume, it’s a fresh restart.

Sorry, the log was filtered to the game process only. Here is an unfiltered humongous log: log2.txt (1.6 MB)

The OpenGLClear error from above is on line 12,328. Yeah, it’s a big file.

0 Likes

#19

I see. I’m not sure this something new though. Is the iPhone XR the only device that returns width/height 0 when returning?

0 Likes

#20

It’s the only device we’re seeing the problem on. iPhone 11 Pro - fine.

0 Likes