Sign in to follow this  

[.net] Pinvoke callback access violation.

This topic is 4309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, perhaps someone here has some experience with pinvoke and can give me a helpfull hint. Here is my problem: I am using Pinvoke from c# (dotnet 2.0 beta) to access an unmanageddll (ODE.dll) and everyting works just dandy except for two important calls that use a callback (dSpaceCollide & dSpaceCollide2). These two calls may call the passed in callback a number of times. Everyting seems to go swimmingly I get the first callback and the paremeters are correct, but I only get one and then I get an AccessViolationException (Accessing protected memeory). I am at my wits end. I have tried fixing all of the params to the function, Tweaking all of the values even using GCHandle to try and protect the callback and I still get an Access violation. I have even gone so far as to study the source of the unmanaged library, suspecting that it might be something internal to the dll -- though I now believe that that is unlikely. If anyone has any idea what is going on here I could really use the help. Thanks.

Share this post


Link to post
Share on other sites
Alright, if anyone is interested I solved the problem. After trying many, many different attribute combinations I found that putting a [UnmanagedFunctionPointer(CallingConvention.Cdecl)] on my delegate declration fixed the Access Violation. I still don't really understand why, but oh well.

Share this post


Link to post
Share on other sites
If you're using Tao.Ode, there are also a couple of post processings that you need to run. There's a working compilation of Tao.Ode.dll that comes with OdeDotNet, check out the CVS and you should have it. Terry and I just got Seriema's ODE collision detection example working in it [wink].

Make sure to join the OdeDotNet Forums and keep us informed of your progress. It's still a very young project so it needs as much help as it can get.

Share this post


Link to post
Share on other sites
Wow, this is digging up an old one.
Truth is I have long since abandoned ODE in favor of Newton. In the future I would like to have some physics agnostics.
That said, the [UnmanagedFunctionPointer(CallingConvention.Cdecl)] applies to Newton callbacks as well.

Share this post


Link to post
Share on other sites

This topic is 4309 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this