yoshinoToylogic / bulletsharp

Automatically exported from code.google.com/p/bulletsharp
MIT License
0 stars 0 forks source link

Fatal error on application exit after adding a KinematicCharacterController #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

I am implementing a kinematic character controller according to the respective 
Bullet demo sample. The controller initialization code follows below.

public void AddPlayer(Matrix initialWorld, float mass, string name)
        {
            PairCachingGhostObject pcgo = new PairCachingGhostObject();
            pcgo.WorldTransform = initialWorld;
            _broadPhase.OverlappingPairCache.SetInternalGhostPairCallback(new GhostPairCallback());
            ConvexShape colShape = new CapsuleShape(0.5f, 2.0f);
            pcgo.CollisionShape = colShape;
            pcgo.CollisionFlags = CollisionFlags.CharacterObject;
            ch = new KinematicCharacterController(pcgo, colShape, 0.35f);
            _dynamicsWorld.AddCollisionObject(pcgo, CollisionFilterGroups.CharacterFilter);
            _dynamicsWorld.AddAction(ch);
        }

If I don't create a kinematic character at all the application exits fine.

What is the expected output? What do you see instead?

The application seems to run fine, but on exit I get the following error 
message:

FatalExecutionEngineError was detected:
The runtime has encountered a fatal error. The address of the error was at 
0x6b0cf852, on thread 0x13e0. The error code is 0xc0000005. This error may be a 
bug in the CLR or in the unsafe or non-verifiable portions of user code. Common 
sources of this bug include user marshaling errors for COM-interop or PInvoke, 
which may corrupt the stack.

What version of the product are you using? On what operating system?

-Latest BulletSharp version
-Windows 7 64-bit
-MS VS2010
-XNA 4.0

Thank you for any help!

Original issue reported on code.google.com by ptour...@gmail.com on 4 Oct 2011 at 5:23

GoogleCodeExporter commented 8 years ago
I think the problem here is that the KinematicCharacterController gets disposed 
when the method returns since DynamicsWorld won't keep a reference to it 
(DynamicsWorld only deals with the unmanaged object).

This is probably an issue with the object lifetime management and cleanup in 
BulletSharp. As a temporary fix, you could try to store the new 
KinematicCharacterController in some static array to make it persist until the 
program exits, although I'm not sure that will help. I'll try to look into it 
soon.

Thanks for reporting this!

Original comment by andres.traks on 4 Oct 2011 at 7:13

GoogleCodeExporter commented 8 years ago
Thanks for your answer. I tried keeping a static reference as you suggested, 
unfortunately the problem persists. I hope the issue can be resolved soon. 
Thanks again anyway!

Original comment by ptour...@gmail.com on 4 Oct 2011 at 7:26

GoogleCodeExporter commented 8 years ago
I couldn't actually reproduce the error message with your configuration. Does 
it run fine otherwise?

Original comment by andres.traks on 4 Oct 2011 at 7:50

GoogleCodeExporter commented 8 years ago
Yes it runs pretty OK. The problem appears on application exit only. If it 
helps, I can post some source code tomorrow, or even send you the small test 
project that produces the error on my machine.

Original comment by ptour...@gmail.com on 4 Oct 2011 at 8:21

GoogleCodeExporter commented 8 years ago
That would be good.

Original comment by andres.traks on 4 Oct 2011 at 9:12

GoogleCodeExporter commented 8 years ago
Hi again! I have attached a VS2010 solution with the test project I told you 
about yesterday. I hope it makes some sense!

Original comment by ptour...@gmail.com on 5 Oct 2011 at 11:41

Attachments:

GoogleCodeExporter commented 8 years ago
I can see the error, but haven't found the cause yet.

Original comment by andres.traks on 6 Oct 2011 at 6:06

GoogleCodeExporter commented 8 years ago
Hi Andres. In the project I sent you, I created a separate "Player" class that 
internally holds the KinematicCharacterController, the PairCachingGhostObject 
and the ConvexShape and the problem was solved! It is strange though, because 
other than the new class, the process I followed to add the character and 
collision object to the dynamics world, as well as dispose them, was actually 
the same. Anyway, since the problem's solved everything is fine. Thanks again 
for your time!

Original comment by ptour...@gmail.com on 7 Oct 2011 at 10:14

GoogleCodeExporter commented 8 years ago
Well, it's been a while, but I traced it back to this line:
_dynamicsWorld.RemoveCollisionObject(_character.GhostObject);

The GhostObject getter property was creating a new wrapper object for the 
btGhostObject instead of retrieving the existing one. Since the new object 
immediately went out of scope, it also destroyed the btGhostObject, which 
caused the crash. This is fixed in r383.

Thanks again!

Original comment by andres.traks on 9 Jun 2012 at 9:44