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

halfer
  • 19,824
  • 17
  • 99
  • 186
agiro
  • 2,018
  • 2
  • 30
  • 62
  • Please include the error and stacktrace – Stefan Sep 08 '17 at 08:29
  • Thanks for the heads up. Where to find those? (made build for Android) – agiro Sep 08 '17 at 08:29
  • Which IDE are you using? If you run it with a debugger this should be very obvious. If you can only run it in a release build, you might want to consider to log your exceptions. – Stefan Sep 08 '17 at 08:31
  • See [here](https://stackoverflow.com/questions/44690357/how-to-read-debug-log-when-using-android/44690501#44690501) for how to read Unity log on Android. – Programmer Sep 08 '17 at 08:32
  • Thanks to you two. I'm trying to hook it up with Android studio now. In the Editor it's all fine, not even getting exceptions nor unexpected behaviour :/ – agiro Sep 08 '17 at 08:37
  • @Programmer I connected my tablet to Android Studio and could hook up with the logcat as you instructed in the post. I filtered to get only Unity logs and used a full, non-development build. When starting the game, I got some logs, but that works fine. I got the freeze-then-crash, but no log :/ What could have gone wrong? – agiro Sep 08 '17 at 08:53
  • Ok so where is the log? People can't help you without the log. Since you can't provide the log, I suggest you start commenting each line of code until you find which one is causing it then let us know. – Programmer Sep 08 '17 at 08:54
  • edited my comment (mistakenly hit enter while typing). I told the there isn't anything logged when during and after the crash. All I have is loads of logs, but generated only when the game started, when all was fine. – agiro Sep 08 '17 at 08:56
  • I disable my exception handling and make another build, hopefully that will show something – agiro Sep 08 '17 at 08:57
  • lol no errors. during Runtime all I get is `loadAds() call` because of my Admob stuff in there but that never caused an issue. Would Unity's bugs get logged or only my own code? – agiro Sep 08 '17 at 09:06
  • @Programmer disabling `Unity` filter helped to get something. I found a `NullPointerException` and a lot of `W/ResourceType: No package identifier when getting name for resource number`. Edited the question, though it's now full of gibberish in the block quote. – agiro Sep 08 '17 at 09:18
  • I suspect third party plugin since it couldn't find the resources. Remove all the plugins you have one by one and you will find which one is causing the problem. Good luck! – Programmer Sep 08 '17 at 09:26
  • I'm not using any for this :D Just about my luck i guess or Unity doesn't like sharing the same mesh to be used in a `MeshRenderer` and a `Shape` for particle emitter. I filed a bug report as well, plan to answer the question in case I get is sorted out. Thanks for the help anyway, gotta love 'em cryptic Unity issues :D – agiro Sep 08 '17 at 09:29

1 Answers1

2

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.

agiro
  • 2,018
  • 2
  • 30
  • 62
  • Thank you so much for this. My editor was crashing when trying to use SkinnedMeshRenderer.SetBlendShapeWeight() on a mesh that was not readable. – skribbz14 Apr 13 '22 at 14:09