Crash when threading native code

Hello,

I’ve noticed an issue: when threading a native code function the Unity Android app is crashing immediately (I get an Android “Unfortunately myapp has stopped.” message box).
I’ve reproduced it in a very simple way, starting from the libnative.so and AndroidNativePlugin.unitypackage official example available here.
Here is my code:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System.Threading;

public class CallNativeCode : MonoBehaviour {

	[DllImport("native")]
	private static extern float add(float x, float y);

	private static float x,y,res;

	void Start () {
		x = 3;
		y = 10;
		res = -1;
		// Threading an extern function crashes
		Thread t = new Thread(new ThreadStart(NativeAdd));
		t.Start();
		// Direct call to extern function below works
		//NativeAdd();
	}

	void NativeAdd () {
		res = add(x,y);
		// Regular expression below works when threaded
		//res = x + y;
	}

	void OnGUI ()
	{
		GUI.Label (new Rect (15, 125, 450, 100), "adding " + x  + " and " + y + " in native code equals " + res);
	}
}

The C function is rather simple:

float add(float x, float y)
{
	return x + y;
}

Any idea would be greatly appreciated :slight_smile: !

Unity 4.3? This is a know issue, a fix will be released shortly.

Yes, Unity 4.3.1, tested on Android 4.3.
Thanks for your answer, it’s a relief, I’m looking forward the fix!
I’m quite new here, is there a place somewhere else than the forum to check such known issues and bugs?

You could try the issue tracker.

In this particular case it’s this bug:

Thank you very much. For Unity people information I have reported this issue as a bug, case 584826.