Bug? MogreNewt access violations during ContactCallback

aybiss

05-11-2007 12:40:03

Hi all. I've created the following ContactCallback

class BullshitContactCallback : ContactCallback
{
TargetRing owner;

public BullshitContactCallback(TargetRing owner)
: base()
{
this.owner = owner;
}

public static long score = 0;
public override void UserEnd()
{
//score++;
//GameWorld.self.retireGameObject(owner);
}
}

But even with all actual code commented out I'm getting access violations. Sometimes it manifests as 'object is null' exceptions, but mainly they're the 'attempted to read or write etc. etc.' variety. On my quad core Intel with Server 2k3 I have to run for ages to see it happen. On the dual core Athlon with XP it happens instantly that the ContactCallback is triggered.

In case it matters (I can't see how) the TargetRing is a floating cylinder that my 'ship' 'shoots' at. Collision detection is for telling that a TargetRing has been hit by anything with material 'BULLET'. On the quad core where it takes a while to see the problem, I can uncomment the code and my score goes up and my targets 'explode' when I shoot them.

Any suggestions? This one has me stumped and I can't really move on without solving the problem. :x

bleubleu

05-11-2007 15:33:25

Hi!

Two questions :

1) Am I getting that the crash is somewhat random and it is hard to reproduce ?

2) Could you tell me what the retireGameObject() method does. Is it possible that this method deletes one of the Newton Body associated with the contact ?

Mat

aybiss

05-11-2007 21:20:54

Thanks for your reply, but I think I solved it.

To quickly answer your questions, the problem is not 'random' per se, but does exhibit different behaviour on different machines, and yes retireGameObject removes a body from the scene, but again the code crashes without that call, and other calls to that method do work.

OK, so the problem was simply that you *MUST* keep a reference to your ContactCallback classes. If you create the handler like so:

mp.SetContactCallback(new BullshitContactCallback());

your code will crash. If you create the callback and stick it to your class, no crashes. It appears that MOGRE doesn't keep a reference in managed code land, so your callback can be GCed unless you hold at least one reference.


Hope this helps someone,
Aaron.

handcircus

08-11-2007 11:31:17

Thanks Aaron,

Was getting exactly the same, great to see a fix.

Simon