본문 바로가기
Works/Unity 3D

[Unity] 강제로 앱 Crash 만드는 방법

by Vader87 2020. 10. 22.
반응형

Unity 에서 강제 Crash 테스트를 위한 코드 정리

 

1. Windows & Editor

- Utils.ForceCrash

docs.unity3d.com/2018.3/Documentation/ScriptReference/Diagnostics.Utils.ForceCrash.html

 

Unity - Scripting API: Diagnostics.Utils.ForceCrash

You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see: You've told us there are code samples on this page which don't work. If you know ho

docs.unity3d.com

 

2. Android

using UnityEngine;
 
public class Crasher : MonoBehaviour
{
    public void CrashOnAndroid()
    {
        // https://stackoverflow.com/questions/17511070/android-force-crash-with-uncaught-exception-in-thread
        var message = new AndroidJavaObject("java.lang.String", "This is a test crash, ignore.");
        var exception = new AndroidJavaObject("java.lang.Exception", message);
       
        var looperClass = new AndroidJavaClass("android.os.Looper");
        var mainLooper = looperClass.CallStatic<AndroidJavaObject>("getMainLooper");
        var mainThread = mainLooper.Call<AndroidJavaObject>("getThread");
        var exceptionHandler = mainThread.Call<AndroidJavaObject>("getUncaughtExceptionHandler");
        exceptionHandler.Call("uncaughtException", mainThread, exception);
    }
}

 

2020-10-22 12:52:46.462 31660-31863/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.neowiz.games.newmatgo, PID: 31660
    java.lang.Error: FATAL EXCEPTION [main]
    Unity version     : 2018.4.17f1
    Device model      : samsung SM-G887N
    Device fingerprint: samsung/a8sqlteks/a8sqlteks:10/QP1A.190711.020/G887NKSU2CTI2:user/release-keys
    
    Caused by: java.lang.Exception: This is a test crash, ignore.
        at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
        at com.unity3d.player.UnityPlayer.c(Unknown Source:0)
        at com.unity3d.player.UnityPlayer$e$2.queueIdle(Unknown Source:72)
        at android.os.MessageQueue.next(MessageQueue.java:405)
        at android.os.Looper.loop(Looper.java:197)
        at com.unity3d.player.UnityPlayer$e.run(Unknown Source:32)

forum.unity.com/threads/how-to-force-crash-on-android-to-test-crash-reporting-systems.653845/

 

How to force crash on Android to test crash reporting systems

I have been looking for how to force a crash on Android. Techniques like Application.ForceCrash(), infinite loops and throwing exceptions do not crash...

forum.unity.com

 

반응형

댓글