android - Android 中的嵌入式 Unity 使应用程序崩溃

标签 android unity3d

我的 android 程序中有一个嵌入式 Unity3d 项目。 3d 项目在立体 View 中打开良好,可用于 DayDream 耳机(尽管它总是说 Controller 已断开连接,这是一个单独的问题)。当我单击 x 退出 VR View 时,它按预期返回到 Android 应用程序,但 1 秒后应用程序翻转到横向并崩溃。

下面是问题的完整堆栈跟踪:

05-02 15:41:08.907 12645-12770/com.example.kshah.unityvrdisabled I/Unity: ApplicationInfo com.example.kshah.unityvrdisabled version 1.0 build c0ed7691-46f7-416e-9b27-1266306bfb38
05-02 15:41:08.993 12645-12770/com.example.kshah.unityvrdisabled E/Unity: Unable to find AudioPluginMsHRTF
05-02 15:41:08.996 12645-12770/com.example.kshah.unityvrdisabled E/Unity: Unable to find AudioPluginOculusSpatializer
05-02 15:41:08.999 12645-12770/com.example.kshah.unityvrdisabled E/Unity: Unable to find libaudioplugingvrunity
05-02 15:41:09.005 12645-12770/com.example.kshah.unityvrdisabled E/Unity: Unable to find libAudioPluginOculusSpatializer
05-02 15:41:09.025 12645-12770/com.example.kshah.unityvrdisabled 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_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_multisampled_render_to_texture GL_EXT_mul
    tisampled_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_framebuffer_params GL_EXT_clip_cull_distance
     GL_EXT_protected_textures GL_EXT_shader_non_constant_global_initializers GL_QCOM_framebuffer_foveated GL_QCOM_shader_framebuffer_fetch_noncoherent GL_EXT_EGL_image_array GL_NV_shader_noperspective_interpolation
    TrackPlayerBase::TrackPlayerBase()
05-02 15:41:09.059 12645-12770/com.example.kshah.unityvrdisabled I/libOpenSLES: Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
05-02 15:41:09.059 12645-12770/com.example.kshah.unityvrdisabled W/AudioTrack: notificationFrames=-10 clamped to the range -1 to -8
05-02 15:41:09.060 12645-12770/com.example.kshah.unityvrdisabled I/AudioTrack: AUDIO_OUTPUT_FLAG_FAST successful; frameCount 1536 -> 1536
05-02 15:41:09.060 12645-12770/com.example.kshah.unityvrdisabled D/AudioTrack: Client defaulted notificationFrames to 192 for frameCount 1536
05-02 15:41:09.462 12645-12770/com.example.kshah.unityvrdisabled V/MediaRouter: Adding route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
05-02 15:41:09.467 12645-12770/com.example.kshah.unityvrdisabled V/MediaRouter: Selecting route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
05-02 15:41:09.540 12645-12645/com.example.kshah.unityvrdisabled D/SdkConfigurationReader: Fetched params from VrParamsProvider: allow_dynamic_java_library_loading: true
    allow_dynamic_library_loading: true
    allow_vrcore_compositing: false
    allow_vrcore_head_tracking: false
    async_reprojection_config <
      flags: 0
    >
    cpu_late_latching_enabled: true
    daydream_image_alignment: 3
    dim_ui_layer: true
    disallow_multiview: false
    enable_forced_tracking_compat: false
    screen_capture_config <
      allow_casting: true
    >
    touch_overlay_enabled: false
    use_device_idle_detection: true
    use_direct_mode_sensors: false
    use_magnetometer_in_sensor_fusion: true
    use_online_magnetometer_calibration: true
    use_stationary_bias_correction: true
    use_system_clock_for_sensor_timestamps: false
05-02 15:41:09.568 12645-12645/com.example.kshah.unityvrdisabled W/unityvrdisabled: type=1400 audit(0.0:3103): avc: denied { read } for name="stat" dev="proc" ino=4026532357 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:proc_stat:s0 tclass=file permissive=0
05-02 15:41:09.573 12645-12645/com.example.kshah.unityvrdisabled W/native: commandlineflags.cc:1503 Ignoring RegisterValidateFunction() for flag pointer 0xccbd34d0: no flag found at that address
05-02 15:41:09.596 12645-12645/com.example.kshah.unityvrdisabled I/NativeLibraryLoader: VrCore composition disabled, using in-process compositing fallback.
05-02 15:41:09.600 12645-12645/com.example.kshah.unityvrdisabled I/Ion: [vr/gvr/capi/src/gvr_core_api_loader_android.cc:182] Successfully loaded GVR library version 1.140.0 from VrCore (target was 1.120.0).
05-02 15:41:09.636 12645-12645/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/capi/src/gvr.cc:103] Initialized GVR version 1.140.0
05-02 15:41:09.643 12645-12805/com.example.kshah.unityvrdisabled D/NetworkSecurityConfig: No Network Security Config specified, using platform default
05-02 15:41:09.664 12645-12645/com.example.kshah.unityvrdisabled I/GvrLayoutFactory: Successfully loaded GvrLayout from VrCore.
05-02 15:41:09.669 12645-12645/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:1853] In-process composition enabled for Cardboard
    [vr/gvr/render/scanline_racer.cc:1204] Configuring scanline racer for marlin using custom config.
05-02 15:41:09.686 12645-12645/com.example.kshah.unityvrdisabled E/SdkDaydreamTouchListener: Null deviceParams or no alignment markers found.
05-02 15:41:09.686 12645-12651/com.example.kshah.unityvrdisabled I/zygote: Do partial code cache collection, code=41KB, data=61KB
05-02 15:41:09.688 12645-12651/com.example.kshah.unityvrdisabled I/zygote: After code cache collection, code=41KB, data=61KB
    Increasing code cache capacity to 256KB
05-02 15:41:09.704 12645-12645/com.example.kshah.unityvrdisabled E/SdkDaydreamTouchListener: Null deviceParams or no alignment markers found.
05-02 15:41:09.745 12645-12770/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:500] Creating swap chain with id: [1]
05-02 15:41:09.746 12645-12770/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:504]   BufferSpec 0: Size=V[1807, 2291], ColorFormat=Rgba8888, Samples=0, Views=1
    [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:504]   BufferSpec 1: Size=V[1807, 2291], ColorFormat=Rgba8888, Samples=0, Views=1
    [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:517] Destroying swap chain with id: [1]
05-02 15:41:09.747 12645-12770/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:500] Creating swap chain with id: [4]
    [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:504]   BufferSpec 0: Size=V[1265, 1604], ColorFormat=Rgba8888, Samples=0, Views=1
    [vr/gvr/hmd/cardboard/cardboard_api_impl.cc:504]   BufferSpec 1: Size=V[1265, 1604], ColorFormat=Rgba8888, Samples=0, Views=1
05-02 15:41:09.752 12645-12770/com.example.kshah.unityvrdisabled I/ATRACE: Using __system_property_wait to update tags
05-02 15:41:09.752 12645-12817/com.example.kshah.unityvrdisabled I/ATRACE: Updated trace tags to 4097
05-02 15:41:09.849 12645-12770/com.example.kshah.unityvrdisabled D/AudioTrack: stop() called with 37440 frames delivered
05-02 15:41:10.064 12645-12814/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/render/scanline_racer.cc:333] Scanline racing enabled without context sharing
05-02 15:41:10.075 12645-12770/com.example.kshah.unityvrdisabled I/Unity: Could not recreate VR window because GfxDevice is in an invalid state (device lost)

    (Filename:  Line: 901)
05-02 15:41:10.075 12645-12770/com.example.kshah.unityvrdisabled E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
05-02 15:41:10.078 12645-12814/com.example.kshah.unityvrdisabled I/GVR: [vr/gvr/render/late_latcher.cc:204] Late-latching enabled using EXT_external_buffer.
05-02 15:41:10.131 12645-12645/com.example.kshah.unityvrdisabled V/MediaRouter: onRestoreRoute() : route=RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
    Selecting route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
05-02 15:41:10.211 12645-12814/com.example.kshah.unityvrdisabled W/GVR: [vr/gvr/render/scanline_racer.cc:1374] Missed vsync by 115409us (CPU load is too high)
05-02 15:41:10.262 12645-12770/com.example.kshah.unityvrdisabled E/Unity: Error trying to call delegated method pause. null
05-02 15:41:10.262 12645-12770/com.example.kshah.unityvrdisabled D/AudioTrack: stop() called with 14400 frames delivered
05-02 15:41:10.292 12645-12645/com.example.kshah.unityvrdisabled I/Process: Sending signal. PID: 12645 SIG: 9

app homescreen unity opening in stereo mode unity 3d project open app crashing

我的代码附在下面 主要 Activity

public class MainActivity extends AppCompatActivity {

    Button unityVRButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        unityVRButton = (Button)findViewById(R.id.open_unity);
        unityVRButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(MainActivity.this,GameActivity.class));
            }
        });
    }
}

呼唤团结的 Activity

import android.os.Bundle;

import com.rbw.TestVR.UnityPlayerActivity;

/**
 * Created by kshah on 3/15/2018.
 */

public class GameActivity extends UnityPlayerActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
}

可以在此链接找到整个项目

https://drive.google.com/drive/folders/1jFp4pZBMgevB6Z2YgFinYNg6d4KPQJDb?usp=sharing

最佳答案

可能有几个不同的问题。一个是堆栈跟踪中格式错误的 json。

然而,屏幕旋转时的崩溃通常是另外一回事。

似乎有一些任务正在完成对您旧 View 的引用。当应用程序切换到横向时, Activity 将被销毁并重新创建,并且您的所有 View 都会重新创建。如果长时间运行的进程正在引用被垃圾收集的 View ,您的应用程序将会崩溃。

判断这是否真的是问题的一种快速方法是将其添加到调用 Activity 下的 list 中。这将强制调用 Activity 保持纵向模式。如果应用程序在退出后没有崩溃,那么很可能有一个进程持有对已销毁 View 的引用。

  <activity
android:name=".MyActivity"
android:label="@string/title_my_activity"
android:screenOrientation="portrait" />

这里有更多信息: http://code.hootsuite.com/orientation-changes-on-android/

关于android - Android 中的嵌入式 Unity 使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49860716/

相关文章:

Android 在每次配置更改时启动一个异步任务

安卓进度条不显示

c# - 我的子弹随机产生并且不会造成伤害

unity3d - 检查Google Play收据是否足以确保我的播放器偏好数据统一?

git - 如何为 git 准备 Unity 项目(逐步)?

java - 无法在 Activity 内调用 View 对象的方法

android - TextView.getText().toString() 崩溃

android - Android 上的 OpenCV 链接错误

android - 已签名的APK无法正常运行,但调试版本可以正常运行

c# - Unity3D。试图在未经授权的情况下为对象发送命令