Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Pinvoke callback access violation.

Started by turnpast Sep 15, 2004 at 5:37 PM 4 replies 6.2k views
Original Post
turnpast
turnpast
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.
turnpast
turnpast
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.
liquiddark
liquiddark
Probably because a managed function is going to live in protected space inside the CLR. That means that a callback, which will emanate from the wider world of user mode, will be trying to access a piece of memory to which it has no permissions.
No Excuses
Rob Loach
Rob Loach
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.
Rob Loach [Website] [Projects] [
turnpast
turnpast
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.