Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
3.07k stars 1.15k forks source link

[Bug] crash on some android devices, session should catch native session exceptions #921

Closed flankechen closed 2 years ago

flankechen commented 2 years ago

Unity bug report case number Please log a bug at https://unity3d.com/unity/qa/bug-reporting and post the case number here.

Describe the bug Some china version android devices not offcially support arcore somehow could successfully install arcore from store(xiaomi, vivo store...). Sad that mainland china dont have google play store, and it seems that chinese android stores like xiaomi, vivo, oppo store allow not-official-support-arcore devices to install. In this situation, SupportChecker.cs would not work properly. ARSession.state would goes into Ready state. ARSession.CheckAvailability() if (ARSession.state == ARSessionState.Ready) { //yes this goes in }

when creating the session, crash happen like: 12-10 17:05:17.326 11546 11564 E AndroidRuntime: backtrace: 12-10 17:05:17.326 11546 11564 E AndroidRuntime: #00 pc 0000000000f8cb9c /data/app/com.google.ar.core-2efdDNZQpYIGtf9x-3xD1w==/lib/arm64/libarcore_c.so (ArSession_configure+56) (BuildId: cf9926e6d37165f45cff881447f1c714) 12-10 17:05:17.326 11546 11564 E AndroidRuntime: #01 pc 000000000002963c /data/app/com.unity.arfoundation.samples-CTKTXgQgj8VrnXGgn588Og==/lib/arm64/libarpresto_api.so (BuildId: 3281e385200d39bb435129d9c41ba1d9) 12-10 17:05:17.326 11546 11564 E AndroidRuntime: #02 pc 0000000000027468 /data/app/com.unity.arfoundation.samples-CTKTXgQgj8VrnXGgn588Og==/lib/arm64/libarpresto_api.so (BuildId: 3281e385200d39bb435129d9c41ba1d9) 12-10 17:05:17.326 11546 11564 E AndroidRuntime: #03 pc 0000000000026dd0 /data/app/com.unity.arfoundation.samples-CTKTXgQgj8VrnXGgn588Og==/lib/arm64/libarpresto_api.so (BuildId: 3281e385200d39bb435129d9c41ba1d9)

mi6x_crash_log.txt

in java helloar sample, exceptions would throw while creating a session: ` @Override protected void onResume() { super.onResume();

if (session == null) {
  Exception exception = null;
  String message = null;
  try {
    switch (ArCoreApk.getInstance().requestInstall(this, !installRequested)) {
      case INSTALL_REQUESTED:
        installRequested = true;
        return;
      case INSTALLED:
        break;
    }

    // ARCore requires camera permissions to operate. If we did not yet obtain runtime
    // permission on Android M and above, now is a good time to ask the user for it.
    if (!CameraPermissionHelper.hasCameraPermission(this)) {
      CameraPermissionHelper.requestCameraPermission(this);
      return;
    }

    // Create the session.
    session = new Session(/* context= */ this);

  } catch (UnavailableArcoreNotInstalledException
      | UnavailableUserDeclinedInstallationException e) {
    message = "Please install ARCore";
    exception = e;
  } catch (UnavailableApkTooOldException e) {
    message = "Please update ARCore";
    exception = e;
  } catch (UnavailableSdkTooOldException e) {
    message = "Please update this app";
    exception = e;
  } catch (UnavailableDeviceNotCompatibleException e) {
    message = "This device does not support AR";
    exception = e;
  } catch (Exception e) {
    message = "Failed to create AR session";
    exception = e;
  }

  if (message != null) {
    messageSnackbarHelper.showError(this, message);
    Log.e(TAG, "Exception creating session "+message, exception);
    return;
  }
}

// Note that order matters - see the note in onPause(), the reverse applies here.
try {
  session.resume();
} catch (CameraNotAvailableException e) {
  messageSnackbarHelper.showError(this, "Camera not available. Try restarting the app.");
  session = null;
  return;
}

surfaceView.onResume();
displayRotationHelper.onResume();

} ` In this code, UnavailableDeviceNotCompatibleException would catch and throw. and would not crash the app. I think arfoundation session should catch this exceptions and let developer knows and handle this.

Smartphone (please complete the following information):

ankur-unity commented 2 years ago

We don't support this use case.