google-ar / arcore-unity-sdk

ARCore SDK for Unity
https://developers.google.com/ar
Other
1.4k stars 400 forks source link

Black screen in device, White screen in Instant Preview #609

Open Maikol2712 opened 5 years ago

Maikol2712 commented 5 years ago

SPECIFIC ISSUE ENCOUNTERED

Android application show black screen. Instant Preview shows white screen.

VERSIONS USED

07-20 01:47:09.171 16698 16734 I Unity   : SystemInfo CPU = ARMv7 VFPv3 NEON, Cores = 8, Memory = 5634mb
07-20 01:47:09.171 16698 16734 I Unity   : SystemInfo ARM big.LITTLE configuration: 4 big (mask: 0xf0), 4 little (mask: 0xf)
07-20 01:47:09.171 16698 16734 I Unity   : ApplicationInfo com.miguellopez.pruebaxoia version 0.1 build be081f11-ed6d-4586-ac13-cd8b0e3366a6
07-20 01:47:09.171 16698 16734 I Unity   : Built from '2019.1/staging' branch, Version '2019.1.10f1 (f007ed779b7a)', Build type 'Release', Scripting Backend 'mono', CPU 'armeabi-v7a', Stripping 'Disabled'
07-20 01:47:09.371 16698 16734 D Unity   :  GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_EGL_sync GL_OES_vertex_half_float GL_OES_framebuffer_object GL_OES_rgb8_rgba8 GL_OES_compressed_ETC1_RGB8_texture GL_AMD_compressed_ATC_texture GL_KHR_texture_compression_astc_ldr GL_KHR_texture_compression_astc_hdr GL_OES_texture_compression_astc GL_OES_texture_npot GL_EXT_texture_filter_anisotropic GL_EXT_texture_format_BGRA8888 GL_OES_texture_3D GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_QCOM_alpha_test GL_OES_depth24 GL_OES_packed_depth_stencil GL_OES_depth_texture GL_OES_depth_texture_cube_map GL_EXT_sRGB GL_OES_texture_float GL_OES_texture_float_linear GL_OES_texture_half_float GL_OES_texture_half_float_linear GL_EXT_texture_type_2_10_10_10_REV GL_EXT_texture_sRGB_decode GL_EXT_texture_format_sRGB_override GL_OES_element_index_uint GL_EXT_copy_image GL_EXT_geometry_shader GL_EXT_tessellation_shader GL_OES_texture_stencil8 GL_EXT_shader_io_blocks GL_OES_shader_image_atomic GL_OES_sample_variables GL_EXT_texture_border_clamp GL_EXT_multi
07-20 01:47:09.371 16698 16734 D Unity   : sampled_render_to_texture GL_EXT_multisampled_render_to_texture2 GL_OES_shader_multisample_interpolation GL_EXT_texture_cube_map_array GL_EXT_draw_buffers_indexed GL_EXT_gpu_shader5 GL_EXT_robustness GL_EXT_texture_buffer GL_EXT_shader_framebuffer_fetch GL_ARM_shader_framebuffer_fetch_depth_stencil GL_OES_texture_storage_multisample_2d_array GL_OES_sample_shading GL_OES_get_program_binary GL_EXT_debug_label GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_QCOM_tiled_rendering GL_ANDROID_extension_pack_es31a GL_EXT_primitive_bounding_box GL_OES_standard_derivatives GL_OES_vertex_array_object GL_EXT_disjoint_timer_query GL_KHR_debug GL_EXT_YUV_target GL_EXT_sRGB_write_control GL_EXT_texture_norm16 GL_EXT_discard_framebuffer GL_OES_surfaceless_context GL_OVR_multiview GL_OVR_multiview2 GL_EXT_texture_sRGB_R8 GL_KHR_no_error GL_EXT_debug_marker GL_OES_EGL_image_external_essl3 GL_OVR_multiview_multisampled_render_to_texture GL_EXT_buffer_storage GL_EXT_external_buffer GL_EXT_blit_framebuf
07-20 01:47:09.371 16698 16734 D Unity   : fer_params GL_EXT_clip_cull_distance GL_EXT_protected_textures GL_EXT_shader_non_constant_global_initializers GL_QCOM_texture_foveated GL_QCOM_shader_framebuffer_fetch_noncoherent GL_EXT_memory_object GL_EXT_memory_object_fd GL_EXT_EGL_image_array GL_NV_shader_noperspective_interpolation GL_KHR_robust_buffer_access_behavior GL_EXT_EGL_image_storage GL_EXT_blend_func_extended GL_EXT_clip_control
07-20 01:47:12.954 16698 16734 E Unity   : Unable to find arcore_instant_preview_unity_plugin

STEPS TO REPRODUCE THE ISSUE

  1. Create new project
  2. Change platform to Android
  3. Import arcore-unity-sdk-v1.10.0.unitypackage
  4. Import from package manager Multiplayer HLAPI and XR Legacy Input Helpers
  5. Check ARCore Required and Instant Preview Enabled in Project Settings
  6. Check Player Settings > XR Settings > ARCore Supported
  7. Load HelloAR scene.
  8. Build and Run (for black screen) or Play in editor ( for white screen).

WORKAROUNDS (IF ANY)

Restart the android device.

ADDITIONAL COMMENTS

Initially, the application may render the camera fine, but once the problem shows up (random apparently), it does not get fixed until the device is restarted.

When importing the ARCore SDK package, this error shows in console:

Assembly 'Assets/PlayServicesResolver/Editor/Google.IOSResolver_v1.2.105.0.dll' will not be loaded due to errors:
Unable to resolve reference 'Google.VersionHandlerImpl'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Google.JarResolver'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
knightcube commented 5 years ago

Faced this same issue with Unity 2018.4.4f1 and ARCore version 1.9.0. In my case there is black screen in my device and in the instant preview window it displays the camera view of my phone. Pretty weird issue. It is as if my camera is running but i cannot see anything but a black screen in my device and the camera is directly sending the view to the Instant preview window but not to my device.

uffeflarup commented 5 years ago

I have the same problem. On Samsung Galaxy S8, ARCore SDK 1.10.0 and Unity 2019.1.13.

When running our game on the device I randomly get black screen upon startup of an AR scene (it displays the white 3D box logo in the center). Typically I can work around it by simply going to a non-AR scene (like our main menu) and then entering the AR scene again. But for our end-users the camera should work every time they start an AR scene in our game.

I remember this being a problem back in the beta days of ARCore, but I haven't seen it for a long time - until now. It started appearing again like 1-2 weeks ago.

An update to the ARCore plugin was released 25th of July this year, so I'm wondering if it's related to that update.

Any help would be much appreciated. Thanks a lot in advance!

Crashthatch commented 5 years ago

I also see a similar issue on my Samsung Galaxy S8 (ARCore SDK 1.11.0 and Unity 2019.1.0f2). Not sure if it's exactly the same as OP because I don't need to restart to fix it (just close & repoen the app) - sounds more like @uffeflarup 's issue.

I think it's that the camera can't be connected to, and ARCore gives up. In adb logcat I get a lot of messages like:

08-12 16:45:39.281  9938  9992 E native  : status.cc:153 ArStatusErrorSpace::AR_ERROR_DEADLINE_EXCEEDED: Point cloud only available on latest frame;  at third_party/arcore/ar/core/session.cc:1576
08-12 16:45:39.285  9938  9992 W Unity   : Failed to acquire point cloud with status ErrorDeadlineExceeded
08-12 16:45:39.285  9938  9992 W Unity   : GoogleARCoreInternal.FrameApi:TryAcquirePointCloudHandle(IntPtr&)
08-12 16:45:39.285  9938  9992 W Unity   : GoogleARCoreInternal.PointCloudManager:OnUpdate()
08-12 16:45:39.285  9938  9992 W Unity   : GoogleARCoreInternal.ARCoreAndroidLifecycleManager:_OnEarlyUpdate()
08-12 16:45:39.285  9938  9992 W Unity   : System.Action:Invoke()

and

android_camera.cc:1289 Camera 0: State ERROR: Capture session closed.
08-12 16:45:33.577  9938  9938 W native  : session.cc:821 Session::Resume returning generic::deadline_exceeded: Camera 0: State ERROR: Timed out waiting for OPEN => CAPTURING.

After reading your comment, I have worked around it by disabling & re-enabling the AR Session whenever I see a ErrorDeadlineExceeded error. To do this, I made FrameAPI throw an error whenever there was an ErrorDeadlineExceeded error:

Debug.LogWarningFormat("Failed to acquire point cloud with status {0}", status);
if (status == ApiArStatus.ErrorDeadlineExceeded)
{
    throw new PointCloudDeadlineExceededException("Failed to acquire point cloud with status" + status);
}

Then caught the error in ARCoreAndroidLifecycleManager, and called another script which did the restart.

try
{
    NativeSession.OnUpdate(m_CachedFrameHandle);
}
catch(PointCloudDeadlineExceededException e)
{
    Debug.Log("Caught PointCloudException " + e);
    GameObject.FindObjectOfType<restartAR>().restartARController();
}

I also did a restart inside the error check part of ARCoreAndroidLifecycleManager (not sure if this is needed):

if (SessionStatus.IsError() && 
previousSessionStatus.IsError() != SessionStatus.IsError())
{
    // Disable internal session bits so we properly pause the session due to error.
    _FireOnSessionSetEnabled(false);
    m_DisabledSessionOnErrorState = true;

    //Disable and re-enable the session to try to restart.
    GameObject.FindObjectOfType<restartAR>().restartARController();

My restartARController looks like the below, but I'm using the obsolete Unity ARController, so your method of re-initializing ARCore will probably need to be different. I found that the CoRoutine was necessary (presumably because it allows a gap between the disable and re-enable).

public class restartAR : MonoBehaviour
{
    public UnityARInterface.ARController arController;

    public void restartARController()
    {
        Debug.Log("restartARController called.");
        StartCoroutine(restartARRoutine());
    }

    private IEnumerator restartARRoutine()
    {
        Debug.Log("restartARController routine started.");
        yield return new WaitForSeconds(0.1f);
        Debug.Log("restartARController disabling arController...");
        arController.enabled = false;
        yield return new WaitForSeconds(0.1f);
        Debug.Log("restartARController enabling arController...");
        arController.enabled = true;
        Debug.Log("restartARController routine finished.");
    }
}

There are probably more places that should throw the same exception (I imagine it could happen on events other than aquiring the point cloud), and there are probably better ways of restarting the ARCore session, but I tried different ways for quite a while and this was the version that worked reliably for me.

A proper fix (rather than my dodgy workaround) would be very much appreciated!

uffeflarup commented 5 years ago

@Crashthatch Thanks a lot for sharing this. I'll probably end up making something similar also.

But like you, I also think that a proper fix from the ARCore team would be the correct solution.

mr-yamraj commented 4 years ago

I faced the same issue but was able to resolve it. After installing Multiplayer HLAPI and XR Legacy Input Helpers. The Multithreaded rendering option pops up, you need to uncheck it. And need to make sure in XR settings after checking ARCore Supported there is no warnings. In my case the waring was to remove one entry from the graphics api, which I did And camera popped up.