简体   繁体   English

使用对象的网格物体作为粒子系统的发射器时,内置的Unity游戏崩溃

[英]Built Unity game crashes when using object's mesh as emitter for particle system

I have scenes with some basic flame effect. 我的场景具有一些基本的火焰效果。 Its max particle count is 20 and there are not more than 4-5 instances active on the screen at once. 它的最大粒子数为20,并且一次在屏幕上活动的实例不超过4-5个。 I even checked the profiler but the memory usage was around 150 MB maximum. 我什至检查了探查器,但最大内存使用量约为150 MB。

Given these, all runs fine in the editor but in build once the particles become visible, the game crashes every time. 有了这些,所有的一切都可以在编辑器中正常运行,但是在构建中,一旦粒子变得可见,游戏就会每次崩溃。 I tested this on a virtual Nexus tablet. 我在虚拟Nexus平板电脑上进行了测试。 I'm using Unity 2017.1.1. 我正在使用Unity 2017.1.1。

The built game crashes on PC as well (made a final build for PC, using the same PC). 内置的游戏也会在PC上崩溃(使用同一台PC最终构建了PC)。 The strange thing is though, the code I show runs fine. 不过,奇怪的是,我显示的代码运行良好。 It just gets the mesh from a MeshFilter to add it to the particle system as emitter. 它只是从MeshFilter获取网格, MeshFilter将其作为发射器添加到粒子系统中。 As this happens in the Awake and the level actually starts running, the code doesn't give errors. 由于这在Awake发生,并且关卡实际上开始运行,因此代码不会给出错误。 The issue is only when the mesh is actually being used on the particle system. 问题仅在于在粒子系统上实际使用了网格时。

I was able to trace the issue back to the few following lines: 我能够将问题追溯到以下几行:

var mf = 
transform.parent.gameObject.GetComponentFromParentRecursive<MeshFilter>();

if (mf != null && mf.mesh != null)
{
    var sh2 = system.shape;
    sh2.mesh = mf.mesh;
    return;
}


public static class GetComponentRecursive
{
    /// <summary>
    /// Returns the first Component (T) found on the parent or its children
    /// = the gameobjects on the same level as this is called on.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="g"></param>
    /// <returns></returns>
    public static T GetComponentFromParentRecursive<T>(this GameObject g)
        where T : Component
    {
        if(g.transform.parent.GetComponent<T>() != null)
        {
            return g.transform.parent.GetComponent<T>();
        }
        else
        {
            foreach (Transform c in g.transform.parent.transform)
            {
                if(c.GetComponent<T>() != null)
                {
                    return c.GetComponent<T>();
                }
            }
        }
        return null;
    }
}

Please bear in mind that GetComponentFromParentRecursive works, can use it for sprites, no harm done. 请记住, GetComponentFromParentRecursive可以工作,可以将其用于精灵,而不会造成伤害。 When I comment out the first few lines, it doesn't crash(just lost functionality). 当我注释掉前几行时,它不会崩溃(只是失去了功能)。

Any ideas why this might cause a crash? 有什么想法可能会导致崩溃吗? And only in built game? 而且只有内置游戏?

EDIT: 编辑:

When disabled the Unity filter, I think I might have got something. 禁用Unity过滤器后,我想我可能会得到一些帮助。 It has a NullPointerException and a lot of W/ResourceType: No package identifier when getting name for resource number . 它具有NullPointerException和许多W/ResourceType: No package identifier when getting name for resource number

09-08 11:11:49.976 922-922/? 09-08 11:11:49.976 922-922 /? W/ResourceType: No package identifier when getting name for resource number 0x0000001b 09-08 11:11:49.995 13409-13409/? W / ResourceType:获取资源编号0x0000001b的名称时没有包标识符0-08000000 11b 11-08:11:49.995 13409-13409 / D/ActivityThread: SVC-Creating service: CreateServiceData{token=android.os.BinderProxy@42549900 className=com.google.android.gms.udc.service.UdcApiService packageName=com.google.android.gms intent=null} 09-08 11:11:49.998 922-927/? D / ActivityThread:SVC创建服务:CreateServiceData {token=android.os.BinderProxy@42549900 className = com.google.android.gms.udc.service.UdcApiService packageName = com.google.android.gms intent = null} 09- 08 11:11:49.998 922-927 /? D/dalvikvm: GC_CONCURRENT freed 2918K (32059), 32% free 6993K/10216K, paused 8ms+6ms, total 74ms 09-08 11:11:50.006 13409-13409/? D / dalvikvm:GC_CONCURRENT释放了2918K(32059),32%释放了6993K / 10216K,暂停了8ms + 6ms,总计74ms 09-08 11:11:50.006 13409-13409 /? D/ActivityThread: SVC-CREATE_SERVICE handled : 0 / CreateServiceData{token=android.os.BinderProxy@42549900 className=com.google.android.gms.udc.service.UdcApiService packageName=com.google.android.gms intent=null} 09-08 11:11:50.010 13409-13409/? D / ActivityThread:SVC-CREATE_SERVICE已处理:0 / CreateServiceData{token=android.os.BinderProxy@42549900 className = com.google.android.gms.udc.service.UdcApiService packageName = com.google.android.gms intent = null} 09-08 11:11:50.010 13409-13409 /? D/ActivityThread: SVC-BIND_SERVICE handled : 0 / BindServiceData{token=android.os.BinderProxy@42549900 intent=Intent { act=com.google.android.gms.udc.service.START pkg=com.google.android.gms }} 09-08 11:11:50.022 186-186/? D / ActivityThread:处理的SVC-BIND_SERVICE:0 / BindServiceData{token=android.os.BinderProxy@42549900 intent = Intent {act = com.google.android.gms.udc.service.START pkg = com.google.android.gms }} 09-08 11:11:50.022 186-186 /? W/MALI: MTK_AUX_isMTKFormat:168: int MTK_AUX_isMTKFormat(ANativeWindowBuffer_t*): format=1 09-08 11:11:50.024 819-819/? W / MALI:MTK_AUX_isMTKFormat:168:int MTK_AUX_isMTKFormat(ANativeWindowBuffer_t *):format = 1 09-08 11:11:50.024 819-819 /? V/WallpaperService: Visibility change in com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0: 1 09-08 11:11:50.025 819-819/? V / WallpaperService:com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0:1中的可见性更改:09年9月11日11:11:50.025 819-819 /? V/WallpaperService: onVisibilityChanged(true): com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0 09-08 11:11:50.025 819-819/? V / WallpaperService:onVisibilityChanged(true):com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0 09-08 11:11:50.025 819-819 /? V/WallpaperService: Offsets change in com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0: 0.5,0.5 09-08 11:11:50.031 922-922/? V / WallpaperService:com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0:0.5,0.5 09-08 11:11:50.031 922-922 /? D/AbsListView: onWindowFocusChanged: hasWindowFocus=true, this=android.widget.ListView{4206ddb8 V.ED.VC. D / AbsListView:onWindowFocusChanged:hasWindowFocus = true,此= android.widget.ListView {4206ddb8V.ED.VC。 ......ID 0,176-576,176 #7f0e0046 app:id/digital_appwidget_listview} 09-08 11:11:50.032 710-710/? ...... ID 0176-576,176#7f0e0046 app:id / digital_appwidget_listview} 09-08 11:11:50.032 710-710 /? D/PhoneStatusBar: setSystemUiVisibility vis=c0000700 mask=ffffffff oldVal=700 newVal=c0000700 diff=c0000000 09-08 11:11:50.034 710-710/? D / PhoneStatusBar:setSystemUiVisibility vis = c0000700 mask = ffffffff oldVal = 700 newVal = c0000700 diff = c0000000 09-08 11:11:50.034 710-710 /? D/BarTransitions.PhoneStatusBarView: MODE_OPAQUE -> MODE_TRANSLUCENT animate=false 09-08 11:11:50.036 186-307/? D / BarTransitions.PhoneStatusBarView:MODE_OPAQUE-> MODE_TRANSLUCENT animate = false 09-08 11:11:50.036 186-307 /? I/BufferQueue: com.android.phasebeam.PhaseBeamWallpaper [queue] fps:0.05, dur:39249.01, max:39171.83, min:77.18 09-08 11:11:50.037 186-186/? I / BufferQueue:com.android.phasebeam.PhaseBeamWallpaper [队列] fps:0.05,dur:39249.01,max:39171.83,min:77.18 09-08 11:11:50.037 186-186 /? I/BufferQueue: com.android.phasebeam.PhaseBeamWallpaper [release] fps:0.05, dur:39239.19, max:39160.33, min:78.86 09-08 11:11:50.039 17428-17440/? I / BufferQueue:com.android.phasebeam.PhaseBeamWallpaper [发布] fps:0.05,dur:39239.19,max:39160.33,min:78.86 09-08 11:11:50.039 17428-17440 /? V/SurfaceView: this = vjd{42785900 VE.... ......ID 0,0-1280,720} got resized: w=1280 h=720, cur w=-1 h=-1 09-08 11:11:50.040 710-710/? V / SurfaceView:此= vjd {42785900 VE .... ...... ID 0,0-1280,720}的大小已调整:w = 1280 h = 720,当前w = -1 h = -1 09- 08 11:11:50.040 710-710 /? D/BarTransitions.PhoneStatusBarView: applyModeBackground oldMode=MODE_OPAQUE newMode=MODE_TRANSLUCENT animate=false 09-08 11:11:50.042 710-710/? D / BarTransitions.PhoneStatusBarView:applyModeBackground oldMode = MODE_OPAQUE newMode = MODE_TRANSLUCENT animate = false 09-08 11:11:50.042 710-710 /? D/BarTransitions.NavigationBarView: MODE_OPAQUE -> MODE_TRANSLUCENT animate=true 09-08 11:11:50.042 710-710/? D / BarTransitions.NavigationBarView:MODE_OPAQUE-> MODE_TRANSLUCENT animate = true 09-08 11:11:50.042 710-710 /? D/BarTransitions.NavigationBarView: applyModeBackground oldMode=MODE_OPAQUE newMode=MODE_TRANSLUCENT animate=true 09-08 11:11:50.042 13409-13559/? D / BarTransitions.NavigationBarView:applyModeBackground oldMode = MODE_OPAQUE newMode = MODE_TRANSLUCENT animate = true 09-08 11:11:50.042 13409-13559 /? D/SQLiteDatabase: beginTransaction() 09-08 11:11:50.047 922-922/? D / SQLiteDatabase:beginTransaction()09-08 11:11:50.047 922-922 /? V/InputMethodManager: onWindowFocus: com.android.launcher3.AppsCustomizeTabHost{42312918 VFE..... .F....I. V / InputMethodManager:onWindowFocus:com.android.launcher3.AppsCustomizeTabHost {42312918 VFE ...... F .... I。 0,0-1280,800 #7f10002b app:id/apps_customize_pane} softInputMode=288 first=true flags=#d910100 09-08 11:11:50.048 922-922/? 0,0-1280,800#7f10002b app:id / apps_customize_pane} softInputMode = 288 first = true flags =#d910100 09-08 11:11:50.048 922-922 /? V/InputMethodManager: START INPUT: com.android.launcher3.AppsCustomizeTabHost{42312918 VFE..... .F....I. V / InputMethodManager:开始输入:com.android.launcher3.AppsCustomizeTabHost {42312918 VFE ...... F .... I。 0,0-1280,800 #7f10002b app:id/apps_customize_pane} ic=null tba=android.view.inputmethod.EditorInfo@4234f6e8 controlFlags=#105 09-08 11:11:50.049 641-908/? 0,0-1280,800#7f10002b app:id / apps_customize_pane} ic = null tba=android.view.inputmethod.EditorInfo@4234f6e8 controlFlags =#105 09-08 11:11:50.049 641-908 /? V/InputMethodManagerService: windowGainedFocus: android.os.BinderProxy@42823bf0 controlFlags=#105 softInputMode=#120 windowFlags=#d910100 09-08 11:11:50.050 710-964/? V / InputMethodManagerService:windowGainedFocus:android.os.BinderProxy@42823bf0 controlFlags =#105 softInputMode =#120 windowFlags =#d910100 09-08 11:11:50.050 710-964 /? D/KeyguardViewMediator: isInputRestricted: showing=false, needReshow=false, provisioned=true 09-08 11:11:50.051 641-908/? D / KeyguardViewMediator:isInputRestricted:正在显示=否,needReshow =否,已配置=真09-08 11:11:50.051 641-908 /? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 3549 uid 10097 09-08 11:11:50.054 922-922/? W / InputMethodManagerService:得到RemoteException发送setActive(false)通知给pid 3549 uid 10097 09-08 11:11:50.054 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010303 09-08 11:11:50.057 922-922/? W / ResourceType:获取资源号0x9c010303的名称时没有已知的程序包09-08 11:11:50.057 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010104 09-08 11:11:50.058 922-922/? W / ResourceType:获取资源号0x9c010104的名称时没有已知的程序包09-08 11:11:50.058 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010204 09-08 11:11:50.059 922-922/? W / ResourceType:获取资源号0x9c010204的名称时没有已知的程序包09-08 11:11:50.059 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010304 09-08 11:11:50.060 922-922/? W / ResourceType:获取资源号0x9c010304的名称时没有已知的程序包09-08 11:11:50.060 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010404 09-08 11:11:50.060 831-842/? W / ResourceType:获取资源号0x9c010404的名称时没有已知的程序包09-08 11:11:50.060 831-842 /? W/Binder: Caught a RuntimeException from the binder stub implementation. W / Binder:从活页夹存根实现中捕获了RuntimeException。 java.lang.NullPointerException at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280) at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129) at android.os.Binder.execTransact(Binder.java:404) at dalvik.system.NativeStart.run(Native Method) 09-08 11:11:50.060 831-842/? android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)处com.android.internal.view.IInputMethod $ Stub.onTransact(IInputMethod.java:129)处android.os.Binder.execTransact( Binder.java:404)在dalvik.system.NativeStart.run(Native Method)09-08 11:11:50.060 831-842 /? W/System.err: java.lang.NullPointerException 09-08 11:11:50.060 922-922/? W / System.err:java.lang.NullPointerException 09-08 11:11:50.060 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010504 09-08 11:11:50.060 831-842/? W / ResourceType:获取资源编号0x9c010504 09-08 11:11:50.060 831-842 /的名称时没有已知的程序包? W/System.err: at android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280) 09-08 11:11:50.061 831-842/? W / System.err:位于android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280)09-08 11:11:50.061 831-842 /? W/System.err: at com.android.internal.view.IInputMethod$Stub.onTransact(IInputMethod.java:129) 09-08 11:11:50.061 831-842/? W / System.err:位于com.android.internal.view.IInputMethod $ Stub.onTransact(IInputMethod.java:129)09-08 11:11:50.061 831-842 /? W/System.err: at android.os.Binder.execTransact(Binder.java:404) 09-08 11:11:50.061 831-842/? W / System.err:位于android.os.Binder.execTransact(Binder.java:404)09-08 11:11:50.061 831-842 /? W/System.err: at dalvik.system.NativeStart.run(Native Method) 09-08 11:11:50.061 922-922/? W / System.err:在dalvik.system.NativeStart.run(本机方法)09-08 11:11:50.061 922-922 /? W/ResourceType: No known package when getting name for resource number 0x9c010604 09-08 11:11:50.062 186-1008/? W / ResourceType:获取资源号0x9c010604 09-08 11:11:50.062 186-1008 /时没有已知软件包 I/BufferQueue: StatusBar [queue] fps:1.18, dur:1693.94, max:991.08, min:702.86 09-08 11:11:50.066 13409-13559/? I / BufferQueue:StatusBar [队列] fps:1.18,dur:1693.94,max:991.08,min:702.86 09-08 11:11:50.066 13409-13559 /? D/SQLiteDatabase: endTransaction() 09-08 11:11:50.068 922-922/? D / SQLiteDatabase:endTransaction()09-08 11:11:50.068 922-922 /? D/ListView: measureHeightOfChildren adapter=android.widget.RemoteViewsAdapter@41f35008, startPosition=0, endPosition=-1, maxHeight=121, this=android.widget.ListView{4206ddb8 V.ED.VC. D / ListView:measureHeightOfChildren适配器= android.widget.RemoteViewsAdapter @ 41f35008,startPosition = 0,endPosition = -1,maxHeight = 121,this = android.widget.ListView {4206ddb8V.ED.VC。 ......ID 0,176-576,176 #7f0e0046 app:id/digital_appwidget_listview} 09-08 11:11:50.069 186-186/? ...... ID 0176-576176#7f0e0046 app:id / digital_appwidget_listview} 09-08 11:11:50.069 186-186 /? I/BufferQueue: StatusBar [release] fps:1.18, dur:1692.43, max:989.53, min:702.90 09-08 11:11:50.070 186-1083/? I / BufferQueue:StatusBar [发布] fps:1.18,dur:1692.43,最大:989.53,最小:702.90 09-08 11:11:50.070 186-1083 /? I/BufferQueue: NavigationBar [queue] fps:0.03, dur:39424.04, max:39424.04, min:39424.04 09-08 11:11:50.071 710-710/? I / BufferQueue:NavigationBar [队列] fps:0.03,dur:39424.04,max:39424.04,min:39424.04 09-08 11:11:50.071 710-710 /? D/PhoneStatusBar: Status bar WINDOW_STATE_SHOWING 09-08 11:11:50.078 922-922/? D / PhoneStatusBar:状态栏WINDOW_STATE_SHOWING 09-08 11:11:50.078 922-922 /? D/Launcher3: AppsCustomizePagedView, onMeasure mIsInEditMode = false1073743104 1073742535 1280 711 09-08 11:11:50.079 922-922/? D / Launcher3:AppsCustomizePagedView,onMeasure mIsInEditMode = false1073743104 1073742535 1280 711 09-08 11:11:50.079 922-922 /? W/ResourceType: No package identifier when getting name for resource number 0x00000001 W / ResourceType:获取资源号0x00000001的名称时没有包标识符

The reason it didn't work was that one cannot use - for no apparent reason - the same mesh (same by reference) on the MeshFilter as well as the particle system's Emission Shape . 它不起作用的原因是,没有理由-不能使用-在MeshFilter以及粒子系统的Emission Shape上使用相同的网格(按引用相同)。 For that I had to make a full copy like so: 为此,我必须像这样制作完整副本:

if (mf.mesh.isReadable)
{
    Mesh myAwesomeNewMeshForNoApparentReason2 = new Mesh();
    myAwesomeNewMeshForNoApparentReason2.Clear();
    myAwesomeNewMeshForNoApparentReason2.name = mf.gameObject.name + "_NewMesh";
    myAwesomeNewMeshForNoApparentReason2.vertices = mf.sharedMesh.vertices;
    myAwesomeNewMeshForNoApparentReason2.triangles = mf.sharedMesh.triangles;
    myAwesomeNewMeshForNoApparentReason2.uv = mf.sharedMesh.uv;
    var sh2 = system.shape;
    sh2.mesh = myAwesomeNewMeshForNoApparentReason2;
    return;
}

And make sure the object is not marked as static . 并确保该对象未标记为static This way I could get it to work. 这样我可以使它工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM