How to use Texture2D.CreateExternalTexture?

Hey guys,

I use a software called vvvv to generate graphic stuff and in the end I get a texture out of the renderer. Now I want to use this texture in unity. In vvvv I can use shared texture and get a pointer to the texture in memory.
Now I thought I could use the Texture2D.CreateExternalTexture function from unity to get access to this texture.

Here is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SharedTexture : MonoBehaviour {

    System.IntPtr pointer;
   // Use this for initialization
   void Start () {
        pointer = new System.IntPtr(1073760258);
      

    }
  
   // Update is called once per frame
   void Update () {
        Texture2D tex = Texture2D.CreateExternalTexture(1920,1080,TextureFormat.RGBA32,false,false, pointer);
        GetComponent<Renderer>().material.mainTexture = tex;
    }
}

where the number is the pointer.

But when I start this Unity instantly crashes. Do you know any solution for my problem?

Thank you very much!!

Reading the docs, CreateExternalTexture provides a means to get at a texture somewhere in your own process space, perhaps a texture that a native plugin under Unity3D made for you, for instance. They specifically enumerate certain supported formats in the documentation.

Your vvvv program I assume is a completely different process running in a completely different process space. Unity (or any other user level process) cannot reach into an arbitrary block of memory of another process. Any pointer address you get from one program is meaningless to the another program, which is one of the fundamentals of memory protection.

If your vvvv program is a plugin running under Unity, then you might be able to make this work, but you’re going to need to get the texture address out of the plugin and back to Unity after it is made, and after it is possibly “pinned” in place, depending on whether vvvv uses managed memory or not.