Calling C++ Plug-In with pixel data pointer

Hi,
I am writing a plug-in where I need access to a Texture2D’s pixels, as a pixel pointer. I don’t want to pass the graphics API texture handle, I need the raw pixel data. The Texutre2D format is RGB24 (I don’t want Alpha).

NativeArray pixelData = m_texture.GetPixelData(0);
void * ptr = NativeArrayUnsafeUtility.GetUnsafePtr(pixelData);

I get this error: Pointers and fixed size buffers may only be used in an unsafe context.

I’ve gone into the PLAYER settings and enabled Allow ‘unsafe’ Code, and I still get the same error.
Any ideas? Thank you.

You need to wrap in unsafe context.

unsafe
{
\\you code here
}