Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Calling a Plugin function from a non-UI Thread

$
0
0
Hi, I'm building an Android plugin that can take a picture. The problem is, the picture is not instantly ready and the Unity application follows its course while the picture is being treated. So what I'm currently doing is putting my main Thread to sleep 2s (arbitrary value) hoping that my picture will be ready by then. It's dirty and unreliable but I can't figure out how to do it differently. Each time I try to call a Plugin function from a Thread my app just crashes. Here is the part where I'm calling the plugin : if (jc != null) { if (!pic_taken) { script_cam_display.stopCam (); // Ask the plugin to take a picture CamPlugin.takePicture (jc); // Dirty Thread.Sleep(2000); // Check if pic is available pic_taken = CamPlugin.picAvailable (jc); if (pic_taken) { // Get the picture data = CamPlugin.getData (jc); if(data != null) { Texture2D tex = new Texture2D (2, 2); tex.LoadImage (data); script_pic_display.displayPicture (tex); } } } } pic_taken = false; script_cam_display.stopCam (); script_cam_display.restartCam (); Any idea on how I could reliably wait for the picture to came in without freezing the UI during an arbitrary number of seconds ?

Viewing all articles
Browse latest Browse all 2383

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>