x


pinning in the memory

Hi, my code is

...
...
Private Color[] cols;
Private GCHandle cols_handle
cols = texture.GetPixels(0);
cols_handle = GCHandle.Alloc(cols, GCHandleType.Pinned);
...
...
<Plugin>myFunction(cols_handle.AddrofPinnedObject());

But I am getting on the last line written above InvalidOperationException: The handle is not of Pinned type System.Runtime.InteropServices.GCHandle.AddrOfPinnedObject()

Please someone tell me WHYYYY I am getting this error !!! while I am clearly setting the handle (cols_handle) to type Pinned ??

I have gone mad.. Help would be highly appreciated.

Thanks

more ▼

asked Jul 16 '10 at 05:56 PM

Arjun gravatar image

Arjun
14 3 3 5

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

2 answers: sort voted first

Are you absoloutely sure that cols_handle is called after being pinned, and isn't freed before being used?

The code itself looks fine, but it'll screw up if the bits where you put ... modify the handle

more ▼

answered Jul 16 '10 at 06:04 PM

Mike 3 gravatar image

Mike 3
30.7k 10 67 255

yes i m sure. infact after getting this error i removed the lines which free the handle. main puzzle is that the same code is running in TextureUnityProject example given in unity3d documentation. i just copied the lines...

Jul 17 '10 at 03:03 AM Arjun

Could you post the exact code you are using?

Jul 17 '10 at 05:43 AM StephanK

Hi, thanks for responding here is the link to the exact code. (code was too long to write here) i hope u could solve the mystery. http://dl.dropbox.com/u/5420677/NewBehaviourScript.cs

Jul 19 '10 at 08:38 AM Arjun
Jul 19 '10 at 08:40 AM Arjun
(comments are locked)
10|3000 characters needed characters left

oh gosh, sorry for wasting ur time i used void start() instead of void Start() so it was not initializing the variables , functions and all now its ok

more ▼

answered Jul 19 '10 at 09:10 AM

Arjun gravatar image

Arjun
14 3 3 5

Heh, just noticed that when I checked, glad it's fixed :)

Jul 19 '10 at 10:13 AM Mike 3
(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:

x33
x11
x6
x1

asked: Jul 16 '10 at 05:56 PM

Seen: 1349 times

Last Updated: Jul 16 '10 at 05:58 PM