filament icon indicating copy to clipboard operation
filament copied to clipboard

When app from background to foreground,_renderer->beginFrame(_swapChain) always returns false.

Open Rankilau opened this issue 2 years ago • 7 comments

Describe the bug I use Filament to develop a iOS app and I have found a problem with it. After app startup, _renderer->beginFrame(_swapChain) return true, render normally, but when the app enters the background, and again enters the foreground, _renderer->beginFrame(_swapChain) always returns false, the model cannot render properly, I printed _renderer and _swapChain, they are not be released, In your experience, what causes this problem in Filament?

To Reproduce 1、Start app, load model, _renderer->beginFrame(_swapChain) returns true 2、app enters background mode 3、app enters foreground mode 4、discover _renderer->beginFrame(_swapChain) always returns false

Expected behavior When app from background to foreground, _renderer->beginFrame(_swapChain) still returns true

Screenshots image

Smartphone (please complete the following information):

  • Device: iPhone12
  • OS:iOS14.5

Rankilau avatar Feb 13 '23 02:02 Rankilau

@bejado Does iOS release rendering surfaces or something when backgrounding apps?

romainguy avatar Feb 13 '23 17:02 romainguy

When an app is backgrounded iOS restricts its use of Metal, which might be affecting things.

Are you continuing to call render even when the app is backgrounded? Filament doesn't have any way of detecting this. Can you try hooking into applicationWillResignActive and pausing Filament calls while the app is in the background?

See also Preparing Your Metal App to Run in the Background.

bejado avatar Feb 13 '23 19:02 bejado

When APP enters the background, the render method stop. But even from the background back to the foreground, the render method is called again, _renderer->beginFrame(_swapChain) also returns false, I'm checking foreground to background, what's happening to the app?

Rankilau avatar Feb 14 '23 02:02 Rankilau

@Rankilau Are you seeing this happen with our unmodified gltf-viewer sample app?

bejado avatar Feb 14 '23 22:02 bejado

@bejado This problem did not happen in the gltf-viewer sample. When I copied the code to our app, this problem would happen. It is possible that code of our app influence.I will check git diff to find out the reason.

Rankilau avatar Feb 16 '23 02:02 Rankilau

@Rankilau Sounds good. One area to look at is how you're scheduling your frame callbacks. The gltf-viewrer uses CADisplayLink.

bejado avatar Feb 16 '23 18:02 bejado

I also have a similar problem, has this problem been solved?

machelel avatar Dec 14 '23 03:12 machelel