1

I'm working with a new version of a facetracker which provides some headerfiles which I used to write a dll file. This file is later used with Unity 3D. Because my Unity version just works with c# I had to write a Wrapper and that is where the trouble started. I don't know why the company from the facetracker decided to change some functions in a way that it is more complicated to work with as with the version before.

Here is the declaration of one specific function from the c++ header:

virtual bool SetFromRawBuffer(const unsigned char * rawImageData, Format format, int width, int height, Origin origin) = 0;

cpp file:

C_API bool IImage_SetFromRawBuffer(IImage *pObj, const unsigned char* rawImageData, IImage::Format format, int width, int height, IImage::Origin origin) {
if(pObj) {
    return pObj->SetFromRawBuffer(rawImageData, format, width, height, origin);
}
return false;

}

c#: (Because I didn't know how to handle the enums I just copied them from the original header to my own enumeration.cs.)

[DllImport(@"C:\Users\mad1Z\Desktop\LiveDriverNativeWrapper NEW\LiveDriveNativeWrapper_packed\Release\LiveDriverNativeWrapper.dll")]
static private extern bool IImage_SetFromRawBuffer(IntPtr pObj, byte[] data, Enumerations.Format format, int width, int height, Enumerations.Origin origin);

definition c#:

public bool SetFromRawBuffer(byte[] data, Enumerations.Format format, int width, int height, Enumerations.Origin picorigin)
    {
        return IImage_SetFromRawBuffer(m_pObj, data, format, width, height, picorigin); 
    }

and here is the function call which crashes Unity 3D:

if (inputFrame.SetFromRawBuffer(data, Enumerations.Format.BGRX8888, 640, 480, Enumerations.Origin.TopLeft))

I'm also not sure if I'm using the correct format. I just get imagedata from my webcam and store it in a buffer (data) which is then send to the FaceTracker.

here the Format definition from the original header file:

/// @brief Each member of the following Format enum represents the order the channels
/// are encountered as one walks the memory, byte by byte, from lower to higher    addresses.
///
/// So for example, RGBX8888 means that walking the memory byte by byte from lower to higher addresses,
/// one would expect to encounter R first, G next, and B and X afterwards.  Equivalently, on little endian
/// machines, if the data is read in word-sized chunks, one would expect to find R in bits 0-7, B in 8-15,
/// G in 16-23, and X in 24-31.
///
/// Often you will see documentation stating that images are RGB. On Windows, however, these are actually laid
/// out in memory as BGR. For instance Windows bitmap BI_RGB format actually has data laid out as BGR in memory.
/// Similarly, in DirectShow, when the webcam format is RGB, the data is laid out BGR.
///
/// Finally, BGRX8888 is the preferred format performance-wise, as all code paths are heavily optimized internally
/// with that layout in mind. For best performance, prefer to provide images in BGRX8888 over other supported formats.
/// @if LIVE_DRIVER_SDK_FACEPAINT
/// In addition, all face painting operations happen on BGRX888 data. Therefore, the image returned to you in
/// IOutputFrameFacePaint::GetFacePaintImage will be in BGRX888 format.
/// @endif
enum Format
{
 // RGB formats
BGRX8888,
RGBX8888,
BGR888,
RGB888,

// Grayscale formats
Intensity8,

// YUV 4:2:2 formats
YUV_UYVY,       // YUV_Y422, YUV_UYNV
YUV_YUY2,       // YUV_YUYV, YUV_YUNV
YUV_YVYU,

// YUV 4:2:0 formats
YUV_NV12,
YUV_NV21,       // YUV_420sp
YUV_YV12,       // YUV_420p
YUV_IYUV,       // YUV_I420

FormatCount,

FORMATERROR = 0
};

If you need some more Information please let me know.

5
  • Have you isolated the enums as the cause of the problem? For example, if the calling convention is wrong, this will cause a similar crash. If not, I'd check to see what the values are and see if you're maybe getting a data type of an unexpected size - consider the declaration enum Format : int { ... } Commented Aug 27, 2013 at 17:38
  • I tried sending null instead of data, which should lead SetFromRawBuffer() to return 0 if the other parameters are correct. But Unity still crashed. There are no other return values for the other parameters if something went wrong... so I'm a bit in the dark here. Commented Aug 27, 2013 at 18:32
  • Well it seems data is indeed the troublemaker here. The debugger said: The expression could not be evaluated. Error ID: BC30707 To correct this error check the syntax of the expression. But what is wrong with my conversion const unisgned char* to byte[]? Commented Aug 29, 2013 at 13:44
  • stackoverflow.com/questions/289076/… might help. To my eyes it should work. Commented Aug 29, 2013 at 14:02
  • now I got this: Type Byte[] cannot be marshaled as an unmanaged structure. Commented Aug 29, 2013 at 14:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.