MethodAccessException on Xbox only

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
cjhazard
Posts: 35
Joined: Mon Aug 01, 2011 8:05 pm

MethodAccessException on Xbox only

Post by cjhazard »

I'm pulling my hair out with this one, and it might be to do with my understanding of the C# language more than anything but I thought this the best place to ask...

I've basically modified the CharacterController class so it derives from Cylinder rather than holding reference to one internally, which means it no longer derives from Updateable (but Cylinder effectively implements ISpaceUpdateable anyway). I still override the OnAdditionToSpace and OnRemoveFromSpace methods as the original CharacterController does but now it has to be 'protected override' rather than 'public override'.

All seems to work very... on my PC... but on the Xbox I get the error...

"An unhandled exception of type 'System.MethodAccessException' occurred in BEPUplugin.dll"

(BEPUplugin.dll is my BEPU wrapper for SunBurn which I'm currently in the process of updating)

It occurs at:

Code: Select all

spaceObject.OnAdditionToSpace(this);
... at the end of the Space.Add() method and ONLY on the Xbox?!?

Is it because EntityBase implements ISpaceObject.OnAdditionToSpace explicitly (and privately)? But then I don't get how it works ok for any other entities I have???? I'm clearly not understanding something, I'm just not sure what. Your help would be greatly appreciated as always.

Thanks.
CJ.
:)


p.s. It's definitely caused by my overriding of OnAdditionToSpace in my CharacterController class because I don't get the error if I comment it out.
cjhazard
Posts: 35
Joined: Mon Aug 01, 2011 8:05 pm

Re: MethodAccessException on Xbox only

Post by cjhazard »

Update:

It appears it's trying to call the wrong OnAdditionToSpace method (but only on the Xbox?!?!). So basically it's trying to call the 'protected' method rather than the explicit one. Seems like a C# bug to me rather than a BEPU one.

I think maybe I'll have to rename...

Code: Select all

protected virtual void OnAdditionToSpace(ISpace newSpace)
... to something else.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: MethodAccessException on Xbox only

Post by Norbo »

Well that's certainly an interesting problem! I am not able to immediately reproduce it, though.

I don't know what would cause that exactly. For now I'll assume that it's not just a plain old bug in the compact framework. Maybe it's some sort of strange reference/version confusion; it's not clear how that would cause this exception, though- I'd assume there would need to be an external library not yet recompiled expecting an older, public access modifier.

A brute force solution might be to just grab the very latest version of BEPUphysics from the development fork and compile everything from the bottom up. Since I can't seem to reproduce it, this may fix it for unknown reasons. (The development fork is pretty stable right now; it's actually got a few garbage-related fixes that 1.2.0 doesn't have.)

On a side note, I generally recommend avoiding inheriting from entity types if possible. It's mainly a matter of convention and organization: an Entity is a collidable object capable of motion, whereas a CharacterController is a bunch of logic and constraints that controls the motion of an Entity.
cjhazard
Posts: 35
Joined: Mon Aug 01, 2011 8:05 pm

Re: MethodAccessException on Xbox only

Post by cjhazard »

Hi Norbo.
Norbo wrote:Maybe it's some sort of strange reference/version confusion; it's not clear how that would cause this exception, though- I'd assume there would need to be an external library not yet recompiled expecting an older, public access modifier.
I'm using the latest BEPU source which is integrated directly into my project rather than referencing any external dll so it can't be that. I thought it might be trying to reference an old version of my SunBurn plugin, but I deleted all the old ones and I still get the issue.

For now I've just renamed two methods in the Entity class like so:

Code: Select all

        void ISpaceObject.OnAdditionToSpace(ISpace newSpace)
        {
            OnAddingToSpace(newSpace);
        }

        protected virtual void OnAddingToSpace(ISpace newSpace)
        {
        }

        void ISpaceObject.OnRemovalFromSpace(ISpace oldSpace)
        {
            OnRemovingFromSpace(oldSpace);
        }

        protected virtual void OnRemovingFromSpace(ISpace oldSpace)
        {
        }
Seems to do the trick!
Norbo wrote:I generally recommend avoiding inheriting from entity types if possible
The reason I inherited from the Cylinder class was because my debug drawer wasn't displaying the cylinder. It seems nice and neat to me to actually just inherit from Cylinder and it works very nicely now.

Cheers.
Post Reply