Start a new topic

Unity UWP - Camera turns OFF when app is minimized and does not restart

 Hello

  • We are using the Unity Professionnal SDK 9.3
  • Unity version is 2020.3.2f1
  • Building for UWP, target devices are PC (Windows 10) and Windows Surface Pro 6, issue is reproductible on both devices
  • Happens on both sample app and our own app

Context:

We use Unity to build our app for UWP on Windows Surface Pro 6 and PC.
"Run in background" is checked in Player Settings.
"Default is Full Screen" is not checked in Player Settings.

When our app is in foreground, everything works fine.
If we open another application on top of our app, or use ALT+TAB, our app keeps running, the camera keeps filming, and the event "OnCameraFrameAvailable" is fired regularly.

Problem :

If the user minimizes the application (by pressing the minimize buttton on the top right corner of the screen of clicking on the app icon on the taskbar), the camera of the device stops (we can see that the light indicator on the device turns off), and we no longer receive new frames.

If the "Default is Full Screen" is checked in Player Settings, this also happens when we use ALT+TAB or open another application on top of our app.

We believe this is a limitation of UWP.
However, when the application is opened again (put in the foreground), the camera does not start again.

We noticed that the WikitudeCamera script uses the "OnApplicationPause" event that should call "Start/StopWikitudeNativeSDK", but the event "OnApplicationPause" is not called on PC and Windows Surface when minimizing the application.
Only the event "OnApplicationFocus" is called, but it is also called at times when the camera is still working properly so we cannot use this.

Also, we have not seen any information from Wikitude components properties or events that could tell us the camera is not accessible anymore.
For now, the only way we can tell is that we no longer receive frames from the "OnCameraFrameAvailable" event.

Question :
  • Have you already encountered this issue ? Is there any workaround to prevent the camera to stop, or a way to make it restart automatically if the app is on the forground again ?

  • We haven't found any easy way to find out if the app was minimized (e.g. an event) or if the camera was shut down on UWP. on PC/Surface Do you know of a solution ?

  • Can you confirme that currently, the only way to restart the WikitudeCamera is to destroy it and all the trackers and create them again ? Or can we disable / enable the GameObject in newer versions of the SDK ?

Please let me know if you need more information.
Thank you for your help,
Thales team.

Hello,


Regarding the 2nd point, we found a way to detect when the app is put to the background/minimized which result in the camera going off :

#if ENABLE_WINMD_SUPPORT
            CoreApplication.EnteredBackground += (sender, args) =>
                {
                    
                };
            
            CoreApplication.LeavingBackground += (sender, args) =>
                {
                    
                };
#endif

 We can now restart the camera when the application comes to the foreground again.


Questions 1 and 3 remain, thank you in advance


Thales team.

 

 

Hello,


Any update or comment on this issue ?


Regards

Hi and sorry for the late response.


Regarding the stopping camera: Unfortunately I couldn't reproduce your issue using our SDK examples (using a Windows Surface Pro 4). Could you download the 9.10 version of our SDK from here and test if the camera is still showing the erroneous behavior? (The samples were temporarly disabled in 9.12 but will be available again in future versions)


If the error doesn't occur any more you could try to check if there are any differences between our sample code and yours which might cause the issue.


Best regards,

Peter

Hello,
Sorry for the delay.

I have been able to perform tests on your SDK 9.10 Samples and the issue persists.

Here is the full setup :

Wikitude SDK : Unity Professional 9.10
Project : SDK 9.10 Samples
Unity Version : 2020.3.2f1
Devices :
    PC :
        Microsoft Windows 10 Entreprise LTSC
        10.0.17763
        HP ZBook Fury 15 G7 Mobile Workstation
        x64
        Integrated HP HD Camera
    Tablet :
        Microsoft Windows 10 Professional
        10.0.19045
        Surface Pro 6
        x64
        Integrated Intel(R) AVStream Camera 2500
       
Build Options in Unity :
- Run In Background : true
- Default is Full Screen : true
- Target Device : Any Device
- Architecture : x64
- Target SDK Version : 10.0.19041.0
- Minimum Platform Version : 10.0.10240.0
- Visual Studio Version : 2022

Building / Starting the application in Debug, Release or Master configuration always produced the same results.

On PC :
    - Building "Executable Only, then launching UWPPlayerLauncher.exe" or "D3D Project, then launching the app in Visual Studio" produced the same results.
    - When app is in Full Screen :
        - Alt+Tab or Open other app from the Taskbar -> Camera stops
        - Reduce the application's window -> Camera stops
    - When app is not in Full Screen :
        - Alt+Tab or Open other app from the Taskbar -> Camera keeps running
        - Reduce the application's window -> Camera stops

On Tablet :
    - The folder containing the "UWPPlayerLauncher.exe" has been transferred to the Tablet, then I launched "UWPPlayerLauncher.exe".
    - The tablet has a "Tablet Mode" that can be activated or not (see screenshot attached).
    - With Tablet Mode ON :
        - When app is in Full Screen :
            - Open other app from the Taskbar -> Camera stops
            - (Reducing the application's window is not possible in Tablet Mode)
        - When app is not in Full Screen :
            - Open other app from the Taskbar -> Camera stops
            - (Reducing the application's window is not possible in Tablet Mode)
    - With Tablet Mode OFF and external Keyboard connected to the Tablet :
        - Same behaviors than PC.

By "Reducing the application's window", I meaning clicking on the top-right corner of the screen on the "reduce" icon. (See screenshot attached).

I hope you can reproduce the issue on your side to give us some feedback.

Regards,
Thales team

Reduce Windows Button.png
(520 Bytes)
Login or Signup to post a comment