Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[WP8] Callback from Native code crashing when creating a Texture2D

Discussion in 'Windows' started by zoooom, Feb 6, 2015.

  1. zoooom

    zoooom

    Joined:
    Feb 8, 2012
    Posts:
    50
    Hi there,

    I'm having a few problems creating a Texture2D after calling back from a C# plugin. Code below.

    Unity:
    Code (csharp):
    1.  
    2. public void GetImage()
    3. {
    4.          MyPlugin.Main.OpenImagePicker(OnGetImage);
    5. }
    6.  
    7. public void OnGetImage(string path)
    8. {
    9.         Debug.Log(path);
    10.         Texture2D texture = new Texture2D(2,2);
    11. }
    12.  
    Plugin:
    Code (csharp):
    1.  
    2. public static void OpenImagePicker(Action<string> callback)
    3. {
    4.         UnityApp.BeginInvoke(() => { callback(path); });
    5. }
    6.  
    The callback is executed fine, and the path is logged in OnGetImage, but as soon as it gets to trying to create a Texture2D, the whole app crashes. If I remove this line it works fine. If anyone has any ideas it would be massively appreciated.

    Edit: Must've been some kind of resource overload, as adding a WaitForEndOfFrame before I create the texture fixes it.
     
    Last edited: Feb 7, 2015
  2. Skatola

    Skatola

    Joined:
    Jan 17, 2013
    Posts:
    45
    Hi Zoooom : )
    Can you explain better your solution for this problem? I am just a novice in coding and i encountered the same problem with your native toolkit asset.
    I took the image and my app crash during the callback for a resource overload i suppose, cause that happen only with more texture on my scene.
    How can i use WaitForEndOfFrame and where? thanks : )