- Home /
Runtime error printing another thread
I outsourced some heavy calculations into another thread like mentioned in this post. After searching for an hour why the calculation did not work I found my mistake - I tried to access an array index which was out of bounds, but the console doesn't show up this runtime error. Is this the default behaviour of unity only printing errors from the main thread? How can I see/print errors which occur in another thread?
Answer by Landern · Aug 25, 2016 at 07:04 PM
Yes this is normal behavior. Create a delegate to use Debug.Log(or whatever) from the main thread.
A delegate is completely unnecessary, Debug.Log() is one of the few functions in Unity that are thread safe. Try putting all your code in a thread in a try-catch block and use a Debug.Log to log it like Andrew mentioned
Answer by andrew-lukasik · Jun 22, 2017 at 08:17 PM
Exceptions on worker threads must be sent to Unity for printing manually. Put your code inside try{} block and print catch using Debug.LogException:
Thread thread = new Thread(
()=> {
try {
/*
Your code goes here
*/
} catch (System.Exception ex) {
Debug.LogException(ex);
}
}
);