嵌入Unity在Android中导致应用程序崩溃

9
我在我的安卓程序中嵌入了一个Unity3d项目。该3d项目可以在DayDream头戴式设备上正常打开以进行立体视图操作(尽管它总是显示控制器断开连接,这是一个单独的问题)。当我点击退出VR视图的X时,它回到了预期的安卓应用程序,但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 modeunity 3d project openapp crashing

以下是我的代码 主活动

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));
            }
        });
    }
}

调用Unity的活动

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


没有代码示例,将很难提供帮助... - N0un
我会添加一些代码。 - Kunal Shah
这可能是一个资源释放问题。也许有一种方法能够在UnityPlayerActivity中释放所有的Unity上下文,你应该确保在回到你的MainActivity之前调用它(例如onPauseonDestroy)。另外,你确定提供了正确的堆栈跟踪吗? - N0un
MalformedJsonException - 这个错误提示存在一个未正确生成的 Json 对象。 - Gordon developer
1个回答

0

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

然而,屏幕旋转时的崩溃通常是其他原因。

似乎有一些任务正在完成,并引用您旧视图的内容。当应用程序切换到横向模式时,活动将被销毁并重新创建,所有视图都将被重新创建。如果长时间运行的进程正在引用已经被垃圾回收的视图,则您的应用程序将崩溃。

快速检查是否实际上存在此问题的方法是在调用活动下添加此内容到您的清单中。这将强制调用活动保持纵向模式。如果应用程序退出后没有崩溃,则很可能存在一个进程,该进程保留对已销毁视图的引用。

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

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


我已经添加了一个竖屏布局的XML文件,以便在旋转方向时不会崩溃。但现在应用程序会短暂地打开一个黑屏,看起来像是要打开Unity,但大约一秒钟后就会关闭并返回应用程序视图。我已经更新了这个问题的堆栈跟踪。 - Kunal Shah

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接