Entity LifeSpan

Discuss any questions about BEPUphysics or problems encountered.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Ok, running into runtime problems now with the space update....

Basically what is happening is that my tower is in the center of the world and it shoots at boxes that come near it.

The problem is that every time the tower shoots a few balls, the game crashes... Kinda like the engine cant handle the number of objects in the space.

Have you ever run into this type of problem?

Thanks, Richard.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

What kind of crash is it? If it is an exception, what are the exception details?

If you're seeing an exception in the space.update, it's usually because of invalid velocities messing up numbers (depending on the exception details, of course). This is commonly triggered externally by setting a velocity that has NaN's or infinities in it (such as normalizing a zero-length vector).

Another possibility is the known sphere-sphere special case bug in v0.10.1 (it's been fixed for the next version). It can occasionally cause errors due do invalid velocities. You can try disabling it by removing the special case from the collision detection system:

Code: Select all

space.simulationSettings.collisionDetection.specialCaseCollisionDetectionHandlers.Remove(new SimulationSettings.CollisionDetectionSettings.EntityTypePair(typeof(Sphere), typeof(Sphere)));
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Thanks bro! That totally fixed it.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Hey bro, i just started having the same crashing error again. But this time it is happening when i change the linear velocity of a box that is moving along my map.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

Make sure that the velocity that you're assigning is actually what you expect. If it's being given an invalid value, that can cause the crash very quickly. There is no known bug associated with the Box entity collision special case in v0.10.1, so it's probably going to be somewhere else.

The exact exception and exception detail would help diagnose it.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Ok here is the error:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="BEPUphysics"
StackTrace:
at BEPUphysics.MotionStateManager.flushWriteBuffer()
at BEPUphysics.Space.updateWithInternalTimeSteps(Single timeSinceLastFrame)
at BEPUphysics.Space.update(Single timeSinceLastFrame)
at PTD.PsychoTowerDefense.PhysicsLoop() in C:\Users\Richard\Desktop\Stuff\College Semesters\Junior 5th\4v95 XNA Game Programmin\Final Project\PTD\BasicSetupDemo\PTD.cs:line 188
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


And i am getting this sometimes when boxes collide(with themselves or the floor). I am pretty sure i am setting the velocity correctly.

Richard
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

Good news and bad news.

Good news: that isn't caused by the value of a velocity that you're setting.

Bad news: there's a very high probability that this is going to be annoying to fix.

By the looks of it, you're running the engine asynchronously in its own physics loop. There's a couple of things that could be going on.

1: Entries in the write buffer are somehow being corrupted.
2: The MotionStateManager could be totally corrupted by invalid access (I'm not sure how this could be accomplished, so probably not it).

I'm going to spend some time trying to reproduce this when I can. In the mean time, any more information about when you set velocities, momentums, or positions or where you set them from (threadwise) will help. If the problem is highly reproducible in your project, you could either send me it or a smaller 'repro version' if you'd like.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Sure ill send it to you if that would make it easier. How do you want me to send it?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

You can use the contact (at) bepuentertainment.com address or the private messaging system, though I'm not sure about the size restrictions on the private messages.

You could also attach it to a forum post if you don't mind it being visible publicly.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Okay, i sent you my project for the crashing problem, so you can take a look at it.

But now for some reason, my projectiles are landing on this imaginary plane above my map. What could cause that?

Thanks, Richard.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

It looks like it is indeed write buffer corruption. Unfortunately, it's not directly fixable externally. I'm going to work on setting up a 0.10.2 release which will address the sphere-sphere bug and this one.

However, for your project, I would highly recommend not running the engine asynchronously. It's a powerful approach in certain circumstances, but it can make development unnecessarily annoying (and time consuming). In your project, there are some queries to the current state of the engine from the gameloop through non-thread safe passages. These areas will be unreliable and fail in very strange, subtle ways that can be nearly impossible to track down. Additionally, adding and removing entities directly will require a synchronization, which will likely stall your game noticeably, resulting in headache-inducing jigs. There's solutions to all of these things, but if you don't need to and you're low on time (as is frequently the case with class projects), it's sometimes best just to take the easy route. Also, you won't encounter any of these crashes if you aren't running it asynchronously.

That's not to say you can't use multithreading; when space.useMultithreadedUpdate is enabled and multiple threads are provided, the physics engine update will speed up considerably by making use of multithreading internally. Externally, you can use it exactly as if it were all single threaded (with a few exceptions related to immediate events). Just call the space's update right from the game's update.

As for the invisible plane, that sort of thing is generally caused by graphics not matching the physics. Check the world matrices for the graphics and compare them with the physics positions.
Rompetoto
Posts: 18
Joined: Wed Oct 28, 2009 9:47 pm

Re: Entity LifeSpan

Post by Rompetoto »

Okay, ill check the graphics/physics matrices stuff.

And this might sound like a dumb question...but how would i make my engine synchronous.

Richard
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Entity LifeSpan

Post by Norbo »

Right now, you're running the physics in its own physics loop, which is set up on a second thread separated from your game loop. That's why it is asynchronous; if you instead just call the space.update from your game's update, it will update alongside your game and be 'synchronous.' An example of this style is shown in the BasicSetupDemo. If you still want to take advantage of multiple threads within the engine, you can check out the MultithreadingDemo. The way to update it is still the same, the setup is just a little different.

More information for asynchronous updating and internal multithreading can be found in the associated pdf on the website:
http://www.bepu-games.com/BEPUphysics/documentation.htm
Post Reply