Can't apply impulses...

Can't apply impulses...

I'm trying to add impulses and forces into my code, just playing with available options but when I try to change velocity, applyImpulse, or applyForce my compler issues a break. it compiles fine until it reaches the code.I have a ball class that holds the hkpRigidBody information for the ball. then I have a function called jump where I implement the applyImpulse function that I call when the up key is pressed.

void Jump()
{
hkVector4 imp(0, g_ball->getMass()*6, 0);
g_ball->applyLinearImpulse(imp);
}

I've tried everything I can think of and just recently rebuilt the program to see if I had made some other kind of error.

When I do run it it breaks here:

// Apply an impulse to the center of mass.
inline void hkpRigidBody::applyLinearImpulse(const hkVector4& imp)
{
HK_ASSERT2(0x1f476204, imp.isOk3(), "Impulse passed to hkpRigidBody::applyLinearImpulse is invalid.");
activate();

-> getRigidMotion()->applyLinearImpulse(imp); <-

}

inside the havok code. Any help would be appreciated.

13 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hey keijityko,

Can you single step into that function and tell me what the value of 'imp' is? Also, is g_ball not null when you call applyLinearImpulse?

Thanks!

Pete Developer Support Engineer Havok www.havok.com

Quoting - havokpete

Hey keijityko,

Can you single step into that function and tell me what the value of 'imp' is? Also, is g_ball not null when you call applyLinearImpulse?

Thanks!

I'll check it asap, my compiler is having some serious mental issues, now I have to reinstall it for the 5th time in the last week.

Quoting - keijityko

I'll check it asap, my compiler is having some serious mental issues, now I have to reinstall it for the 5th time in the last week.

I changed my jump code.

void Jump()
{
hkVector4 imp(0, g_ball->getMass()*6, 0);
if (g_ball != HK_NULL)
{
g_ball->applyLinearImpulse(imp);
}
}

also, when I single stepped into it imp was {0.0, 900.0, 0.0} just as it should be. I also tried to implicity set imp.y to 1 and to 20, no matter what value I have for imp it breaks. Could the issue be that I'm missing a header? it doesn't tell me anything when I compile.

I'm also getting this error durring linking, I do think this is OIS and has nothing to do with my current issue as the program still runs.

First-chance exception at 0x7c81eb33 in Setup.exe: Microsoft C++ exception: OIS::Exception at memory location 0x0013f724..

Hey keijityko,

It will be hard to debug this unless we can find out more about why it's breaking. Are you compiling and running in debug? Also, make sure you're linking against the havok debug libs (they're in Lib/win32_net_9-0/debug_multithreaded). Once you've done this, we should be able to get more information about the break, whether it's a crash, or an assert. If it's an assert, let me know what it says and we'll go from there.

As for the error during linking, that looks like a problem with visual studio. I'm not sure what's going on there, but I'd guess maybe you should try cleaning and rebuilding?

Let me know how it goes,
-Pete

Pete Developer Support Engineer Havok www.havok.com

Quoting - havokpete

Hey keijityko,

It will be hard to debug this unless we can find out more about why it's breaking. Are you compiling and running in debug? Also, make sure you're linking against the havok debug libs (they're in Lib/win32_net_9-0/debug_multithreaded). Once you've done this, we should be able to get more information about the break, whether it's a crash, or an assert. If it's an assert, let me know what it says and we'll go from there.

As for the error during linking, that looks like a problem with visual studio. I'm not sure what's going on there, but I'd guess maybe you should try cleaning and rebuilding?

Let me know how it goes,
-Pete

I have it linked to those libraries, unfortunately it doen't give me any asserts or error warnings, the only thing it tells me is that Setup.exe has triggered a breakpoint. I also thought to try and make sure it was active before calling applyLinear Impulse:

void Jump()
{
g_ball->activate();
hkVector4 imp(0, g_ball->getMass()*6, 0);
if (g_ball != HK_NULL)
{
g_ball->applyLinearImpulse(imp);
}
}

but this led to another problem, it breaks on the line declaring the hkVector4 for some reason. it seems that I can't call any of g_balls functions properly without it creating a breakpoint.

Hey keijityko,

It sounds like g_ball is null or otherwise not valid when you try to call it's member functions. As a quick check, can you make sure that g_ball is not null or invalid before you call getMass()? If it is null or invalid, the problem lies there, and we need to find out why and make sure it's set up properly before calling it's member functions.

Thanks!

Pete Developer Support Engineer Havok www.havok.com

I'm not sure what's going wrong, g_ball is most definately not null, I'm not sure if some part of it is invalid but getMass() does return the correct mass. Here's my ball class, could it have to do with the fact that I pass pointers to the physicsWorld into the constructor of the ball?

class Ball
{
protected:
hkpRigidBody* g_ball;
SceneNode* node;
Entity* ent;

public:
Ball(SceneManager* mgr, hkpWorld* physicsWorld)
{
ent = mgr->createEntity("ball", "sphere.mesh");
node = mgr->getRootSceneNode()->createChildSceneNode("ball", Vector3::ZERO);
node->attachObject(ent);
ent->setCastShadows(true);

const hkReal radius = 2.0f;
const hkReal sphereMass = 150.0f;

hkVector4 relPos( 10.0f,radius + 20.0f, -50.0f );

hkpRigidBodyCinfo info;
hkpMassProperties massProperties;
hkpInertiaTensorComputer::computeSphereVolumeMassProperties(radius, sphereMass, massProperties);

info.m_mass = massProperties.m_mass;
info.m_centerOfMass = massProperties.m_centerOfMass;
info.m_inertiaTensor = massProperties.m_inertiaTensor;
info.m_shape = new hkpSphereShape( radius );
info.m_position = relPos;
info.m_friction = 0.5f;
info.m_restitution = 0.9;
info.m_motionType = hkpMotion::MOTION_BOX_INERTIA;

info.m_qualityType = HK_COLLIDABLE_QUALITY_BULLET;

g_ball = new hkpRigidBody( info );
g_ball->addReference();

physicsWorld->addEntity( g_ball );
info.m_shape->removeReference();

hkVector4 pos = g_ball->getPosition();
node->setPosition(pos(0), pos(1), pos(2));
}

~Ball()
{
while (g_ball->getReferenceCount()>0)
{
g_ball->removeReference();
}
}

void Jump()
{
if (g_ball != HK_NULL)
{
g_ball->activate();
hkVector4 imp(0, g_ball->getMass()*6, 0);
g_ball->applyLinearImpulse(imp);
}
}

void transform()
{
hkVector4 pos = g_ball->getPosition();
hkQuaternion quat = g_ball->getRotation();
node->setOrientation(quat(3), quat(0), quat(1), quat(2));
node->setPosition(pos(0), pos(1), pos(2));
}
};

Hey keijityko,

Your code looks good, although you don't need to call activate() on the ball, havok will do that for you. You also don't need to use QUALITY_BULLET unless your spheres are moving very fast, trying using QUALITY_MOVING instead.

I used your code to set up a similar situation within our demo framework, but everything worked without any asserts or crashes. It's hard to say what the problem is, could you try applying an impulse in the constructor, immediately after it's added to the world? If that works without fail, the problem might have to do with when Jump() is being called.

Let me know how it goes!

Pete Developer Support Engineer Havok www.havok.com

Thanks Pete, It works just fine in the constructor where the ball floats upwards slightly before falling again. I will go over the rest of my code, it probably has to do with the class pointer or something else, I appreciate the help.

ok, so I think I found out what's wrong. It seems I can't do any changes to objects in the havok hkpWorld outside of the function in which I create the hkpWorld. Everything runs and displays correctly afterward, I think it might be a missing reference somewhere but this is just a theory. I can step the havoks world forward, but I can't do anything with the ball, apply impulses or anything. Any better ideas? lol

Quoting - keijityko
ok, so I think I found out what's wrong. It seems I can't do any changes to objects in the havok hkpWorld outside of the function in which I create the hkpWorld. Everything runs and displays correctly afterward, I think it might be a missing reference somewhere but this is just a theory. I can step the havoks world forward, but I can't do anything with the ball, apply impulses or anything. Any better ideas? lol

Hey keijityko,

With your new information, I think I know what the problem might be. Every time you call a function that might modify or view the state of the world, you have to call world->markForRead()/Write() and world->unmakrForRead()/Write(). Alternatively, you can call world->lock()/unlock() - markForRead/Write tend to be lighter weight. Check out our demos and you'll see us do this often. So for your jump code, just put a world->markForWrite() at the top and a world->unmarkForWrite() at the bottom, and that should do it!

Let me know if this works!

Pete Developer Support Engineer Havok www.havok.com

holy crap do I feel stupid. Thanks for all the help Pete, you're a game saver. Workin perfectly now.

Login to leave a comment.