Before updating to Windows 10 you may need to return your Pro license. More information here

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, 2010 at 05:41 AM

avatar image

Chris 20
3 3 2 4

(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, 2010 at 04:26 PM

avatar image

AngryAnt ♦♦
4.6k 21 37 89

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, 2010 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



Answers and Comments



asked: Dec 13, 2010 at 05:41 AM

Seen: 2137 times

Last Updated: Dec 13, 2010 at 05:41 AM