Search Unity

Bug AREnvironmentProbe/Manager gives error on Scene unload on Android

Discussion in 'AR' started by coder89, Jun 21, 2021.

  1. coder89

    coder89

    Joined:
    Oct 26, 2018
    Posts:
    29
    Hello,

    I wanted to report a problem with AREnvironmentProbeManager in ARFouncation 4.1.5 (or newer).

    When I unload a scene and uninitialize AR Session, all AREnvironmentProbes are destroyed. During that stage OnDisable is called:

    Code (CSharp):
    1.         void OnDisable()
    2.         {
    3.             if (AREnvironmentProbeManager.instance is AREnvironmentProbeManager manager)
    4.             {
    5.                 // This line causes issue
    6.                 manager.TryRemoveEnvironmentProbe(this);
    7.             }
    8.         }
    AREnvironmentProbeManager has two methods for removing probes:
    - RemoveEnvironmentProbe - which name indicates by convention that it may throw exceptions in case or errors
    - TryRemoveEnvironmentProbe - this one by naming convention indicated that it will return true/false value indicating whether operation was successfull.

    However, it is not the case for TryRemoveEnvironmentProbe...

    Code (CSharp):
    1.         internal bool TryRemoveEnvironmentProbe(AREnvironmentProbe probe)
    2.         {
    3.             if (probe == null)
    4.                 throw new ArgumentNullException(nameof(probe));
    5.  
    6.             if (subsystem == null)
    7.                 return false;
    8.  
    9.             var desc = descriptor;
    10.  
    11.             if ((probe.placementType == AREnvironmentProbePlacementType.Manual) && !desc.supportsRemovalOfManual)
    12.                 throw new InvalidOperationException("Removal of manually placed environment probes are not supported by this subsystem.");
    13.  
    14.             // THIS ONE CAUSES PROBLEMS AS IT THROWS AN UNHANDLED EXCEPTION...
    15.             // Given where this method is called (and since it is internal method) it should not throw any exceptions or they at least should be handled by the caller.
    16.             if ((probe.placementType == AREnvironmentProbePlacementType.Automatic) && !desc.supportsRemovalOfAutomatic)
    17.                 throw new InvalidOperationException("Removal of automatically placed environment probes are not supported by this subsystem.");
    18.  
    19.             if (subsystem.RemoveEnvironmentProbe(probe.trackableId))
    20.             {
    21.                 if (m_PendingAdds.ContainsKey(probe.trackableId))
    22.                 {
    23.                     m_PendingAdds.Remove(probe.trackableId);
    24.                     m_Trackables.Remove(probe.trackableId);
    25.                 }
    26.  
    27.                 probe.pending = false;
    28.                 return true;
    29.             }
    30.  
    31.             return false;
    32.         }
    Note my comment inside the above code snippet.

    Hope this is helpful and it gets fixed in the upcomming release as it is very cumbersome to work with AREnvironmentProbeManager in Debug mode. Also in Release mode it polutes our diagnostics service with a lot or false-positive bug reports.

    /Lukasz
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,822
    The reported exception is safe to ignored. Also, this issue has been fixed in later versions of AR Foundation.
     
  3. coder89

    coder89

    Joined:
    Oct 26, 2018
    Posts:
    29
    Running 4.1.7 and the issue is still there. Or you mean pre-release version of AR Foundation?
     
    kpprt likes this.
  4. kpprt

    kpprt

    Joined:
    Jul 30, 2016
    Posts:
    11
  5. kpprt

    kpprt

    Joined:
    Jul 30, 2016
    Posts:
    11
    I just tested again and the issue was still there with the verified version for 2020.3 LTS, which was 4.1.7. After the update of the AR Foundation, ARCore and ARKit packages to version 4.2.1 the exception was gone.
     
  6. NikodemMSM

    NikodemMSM

    Joined:
    Oct 26, 2016
    Posts:
    1
    Hey everyone,
    I tested this on Unity 2020.3.19f1 with AR Foundation, ARCore & ARKit on 4.2.1 & 4.2.3 (also deleted the .lock file and the package cache after upgrading).

    This issue still persists on my end when unloading the Scene. No harm done, but we use the LunarConsole to Log errors and this pops up regularly on Android.
     
  7. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062