x


Does c# Marshaling work in the webplayer?

Hi, I'm trying to use Marshal.StructureToPtr to convert a structure before sending via a socket to another app. It works in the editor, but crashes on the Marshal.StructureToPtr call in the webplayer.

Heres some example code:

[StructLayout(LayoutKind.Sequential, Pack = 1)]

public struct SENDPOS { public long SendId; public float x,y,z; };

    SENDPOS PlayerPos;
    byte[] arr;
    int len;
    IntPtr ptr;

//(in Start() )

    len = Marshal.SizeOf(PlayerPos);
    arr = new byte[len];
    ptr = Marshal.AllocHGlobal(len);

//in Update()

    Marshal.StructureToPtr( PlayerPos, ptr,false); //<-------- CRASH HERE
    Marshal.Copy(ptr, arr, 0, len);
    ClientSocket.Send(arr, len, SocketFlags.None);

Is marshaling supposed to work in the webplayer, or is this a Unity bug? Or am I doing something wrong in the above code?

more ▼

asked Dec 13 '10 at 05:41 AM

Chris 20 gravatar image

Chris 20
3 1 1 2

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Regardless of whether this should be enabled or not, crashing the browser is always a bug. Please report it using the bug reporter :)

more ▼

answered Dec 13 '10 at 04:26 PM

AngryAnt gravatar image

AngryAnt ♦♦
4.4k 14 19 52

Yep, had filed a bug report already. Seems like it's not supposed to be supported (as that would be unmanaged memory), but the current webplayer just crashes if you try to use it. The best workaround I've found so far is to use Buffer.BlockCopy and BitConverter.GetBytes to convert variables into a block of memory.

Dec 23 '10 at 04:45 PM Chris 20
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1057
x876
x792
x8

asked: Dec 13 '10 at 05:41 AM

Seen: 1713 times

Last Updated: Dec 13 '10 at 05:41 AM