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

1

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. I even checked the profiler but the memory usage was around 150 MB maximum.

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. I'm using Unity 2017.1.1.

The built game crashes on PC as well (made a final build for PC, using the same 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. As this happens in the Awake and the level actually starts running, the code doesn't give errors. 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. 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. It has a NullPointerException and a lot of W/ResourceType: No package identifier when getting name for resource number.

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/? 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/dalvikvm: GC_CONCURRENT freed 2918K (32059), 32% free 6993K/10216K, paused 8ms+6ms, total 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-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/? 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: 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/? D/AbsListView: onWindowFocusChanged: hasWindowFocus=true, this=android.widget.ListView{4206ddb8 V.ED.VC. ......ID 0,176-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/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 [release] 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 V.E..... ......ID 0,0-1280,720} got resized: w=1280 h=720, cur 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.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/SQLiteDatabase: beginTransaction() 09-08 11:11:50.047 922-922/? 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/? V/InputMethodManager: START INPUT: 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/? 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/? W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to 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: No known package when getting name for resource number 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: No known package when getting name for resource number 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/Binder: Caught a RuntimeException from the binder stub implementation. 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/? 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/System.err: at 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: at 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/ResourceType: No known package when getting name for resource number 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/? 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. ......ID 0,176-576,176 #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: NavigationBar [queue] 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/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

c#
unity3d
crash
asked on Stack Overflow Sep 8, 2017 by agiro • edited Sep 14, 2018 by halfer

1 Answer

1

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. 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. This way I could get it to work.

answered on Stack Overflow Sep 9, 2017 by agiro • edited Sep 9, 2017 by agiro

User contributions licensed under CC BY-SA 3.0