Sign in to follow this  

Found the problem, but no the solution, help again

This topic is 2054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

After new ways of usage the debugger explained by a friend and in here..

I think I found the problem, but i dunno yet the solution..

[attachment=8526:mContact.jpg]

Any ideas, clues or expl., are more than welcome.

Thanks for this

Share this post


Link to post
Share on other sites
m_Contact is NULL, meaning it doesn't point to anything. What you're seeing is an indication that you have not set the pointer to a valid address.

Without seeing your code, it's impossible to know [i]why[/i] this is the case.

Share this post


Link to post
Share on other sites
[CODE]
Entity::Entity( int id ) : m_Position( 0.0f, 0.0f, 0.0f ),
m_Velocity( 0.0f, 0.0f, 0.0f ),
m_Acceleration( 0.0f, 0.0f, 0.0f ),
m_LastFrameAcceleration( 0.0f, 0.0f, 0.0f ),
m_ForceAccumulator( 0.0f, 0.0f, 0.0f ),
m_Scale( 1.0f, 1.0f, 1.0f ),
m_ContactNormal( 0.0f, 0.0f, 0.0f ),
m_ContactPoint( 0.0f, 0.0f, 0.0f ),
m_Movement( 0.0f, 0.0f, 0.0f ),
m_Contact( 0 ),
m_Radius( 0.0f ),
m_Damping(0.99f),
m_InverseMass(0.0f),
m_TimeActive(0.0f),
m_Restitution(0.0f),
m_Penetration(0.0f),
m_Friction(0.0f),
m_Tolerance(0.0f),
m_ID( id ),
m_Active(false),
m_Collision(false)
{
[/CODE]

This the Entity.cpp

Thanks very much..

Share this post


Link to post
Share on other sites
[CODE]
#include "Entity.h"
#include <wchar.h>
#include "float.h"
#include "Graphics/RenderItem.h"
using Sfas::Game::Entity;
Entity::Entity( int id ) : m_Position( 0.0f, 0.0f, 0.0f ),
m_Velocity( 0.0f, 0.0f, 0.0f ),
m_Acceleration( 0.0f, 0.0f, 0.0f ),
m_LastFrameAcceleration( 0.0f, 0.0f, 0.0f ),
m_ForceAccumulator( 0.0f, 0.0f, 0.0f ),
m_Scale( 1.0f, 1.0f, 1.0f ),
m_ContactNormal( 0.0f, 0.0f, 0.0f ),
m_ContactPoint( 0.0f, 0.0f, 0.0f ),
m_Movement( 0.0f, 0.0f, 0.0f ),
m_Contact( 0 ),
m_Radius( 0.0f ),
m_Damping(0.99f),
m_InverseMass(0.0f),
m_TimeActive(0.0f),
m_Restitution(0.0f),
m_Penetration(0.0f),
m_Friction(0.0f),
m_Tolerance(0.0f),
m_ID( id ),
m_Active(false),
m_Collision(false)
{
}
Entity::Entity( int id, float scale, float damping ) : m_Position( 0.0f, 0.0f, 0.0f ),
m_Velocity( 0.0f, 0.0f, 0.0f ),
m_Acceleration( 0.0f, 0.0f, 0.0f ),
m_LastFrameAcceleration( 0.0f, 0.0f, 0.0f ),
m_ForceAccumulator( 0.0f, 0.0f, 0.0f ),
m_Scale( scale, scale, scale ),
m_ContactNormal( 0.0f, 0.0f, 0.0f ),
m_ContactPoint( 0.0f, 0.0f, 0.0f ),
m_Movement( 0.0f, 0.0f, 0.0f ),
m_Contact( 0 ),
m_Radius( 0.0f ),
m_Damping(damping),
m_InverseMass(0.0f),
m_TimeActive(0.0f),
m_Restitution(0.0f),
m_Penetration(0.0f),
m_Friction(0.0f),
m_Tolerance(0.0f),
m_ID( id ),
m_Active(false),
m_Collision(false)
{
}
Entity::Entity( int id, const D3DXVECTOR3& pos, float scale, float damping ) : m_Position(pos),
m_Velocity( 0.0f, 0.0f, 0.0f ),
m_Acceleration( 0.0f, 0.0f, 0.0f ),
m_LastFrameAcceleration( 0.0f, 0.0f, 0.0f ),
m_ForceAccumulator( 0.0f, 0.0f, 0.0f ),
m_Scale( scale, scale, scale ),
m_ContactNormal( 0.0f, 0.0f, 0.0f ),
m_ContactPoint( 0.0f, 0.0f, 0.0f ),
m_Movement( 0.0f, 0.0f, 0.0f ),
m_Contact( 0 ),
m_Radius( 0.0f ),
m_Damping(damping),
m_InverseMass(0.0f),
m_TimeActive(0.0f),
m_Restitution(0.0f),
m_Penetration(0.0f),
m_Friction(0.0f),
m_Tolerance(0.0f),
m_ID( id ),
m_Active(false),
m_Collision(false)
{
}
Entity::Entity( int id, const D3DXVECTOR3& pos, const D3DXVECTOR3& scale, float damping ) : m_Position(pos),
m_Velocity( 0.0f, 0.0f, 0.0f ),
m_Acceleration( 0.0f, 0.0f, 0.0f ),
m_LastFrameAcceleration( 0.0f, 0.0f, 0.0f ),
m_ForceAccumulator( 0.0f, 0.0f, 0.0f ),
m_Scale( scale ),
m_ContactNormal( 0.0f, 0.0f, 0.0f ),
m_ContactPoint( 0.0f, 0.0f, 0.0f ),
m_Movement( 0.0f, 0.0f, 0.0f ),
m_Contact( 0 ),
m_Radius( 0.0f ),
m_Damping(damping),
m_InverseMass(0.0f),
m_TimeActive(0.0f),
m_Restitution(0.0f),
m_Penetration(0.0f),
m_Friction(0.0f),
m_Tolerance(0.0f),
m_ID( id ),
m_Active(false),
m_Collision(false)
{
}

Entity::~Entity(void)
{
}
void Entity::Render( Engine::RenderItem * drw )
{
if( m_Active )
{
D3DXMATRIX world;
D3DXMATRIX move;
D3DXMATRIX scale;
D3DXMatrixTranslation( &move, m_Position.x, m_Position.y, m_Position.z );
D3DXMatrixScaling( &scale, m_Scale.x, m_Scale.y, m_Scale.z );

world = scale * move;
drw->Draw( &world );
}
}
void Entity::Update( float dt )
{
if( m_Active )
{
m_ForceAccumulator.y -= ( kGravity * GetMass() );
LinearIntegration( dt );
// Count this frame
m_TimeActive += dt;
}
}
bool Entity::CheckForCollision( const Entity& other )
{
float left1 = m_Position.x - ( m_Scale.x * 0.5f );
float left2 = other.m_Position.x - ( other.m_Scale.x * 0.5f );
float right1 = left1 + m_Scale.x;
float right2 = left2 + other.m_Scale.x;
float top1 = m_Position.y + ( m_Scale.y * 0.5f );
float top2 = other.m_Position.y + ( other.m_Scale.y * 0.5f );
float bottom1 = top1 - m_Scale.y;
float bottom2 = top2 - other.m_Scale.y;
if (bottom1 > top2) return false;
if (top1 < bottom2) return false;
if (right1 < left2) return false;
if (left1 > right2) return false;
// Create the contact information ready for resolution
D3DXVECTOR3 direction = m_Position - other.m_Position;
D3DXVec3Normalize( &direction, &direction );
m_ContactPoint = other.m_Position + ( direction * other.m_Radius );
if( other.m_Collision && top1 >top2 && bottom1 < top2 )
{
m_Penetration = top2 - bottom1;
m_ContactNormal = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
}
return true;
}
void Entity::OnCollision( Entity& other )
{
// Default behavour
SetActive( false );
}
void Entity::LinearIntegration( float dt )
{
// Don't Integrate invalid particles
if (m_InverseMass <= 0.0f)
{
return;
}
// Update current position with velocity
m_Position += ( m_Velocity * dt );
// Calculate acceleration
m_LastFrameAcceleration = m_Acceleration;
m_LastFrameAcceleration += ( m_ForceAccumulator * m_InverseMass );
// Calculate velocity
m_Velocity += ( m_LastFrameAcceleration * dt );
// Damp the velocity to slow the object over time
m_Velocity *= pow(m_Damping, dt);
// Save and clear forces
m_ForceAccumulator.x = m_ForceAccumulator.y = m_ForceAccumulator.z = 0.0f;
}
void Entity::SetMass( float mass)
{
m_InverseMass = ( 1.0f / mass );
}
float Entity::GetMass() const
{
if( m_InverseMass == 0 )
{
return FLT_MAX;
}
else
{
return (1.0f / m_InverseMass );
}
}
float Entity::CalculateSeparatingVelocity( Entity& other )
{
D3DXVECTOR3 relativeVelocity = m_Velocity;
relativeVelocity -= other.GetVelocity();
return D3DXVec3Dot(&relativeVelocity, &m_ContactNormal);
}
void Entity::Resolve(Entity& other, float duration)
{
m_Contact = &other;
ResolveVelocity(duration);
ResolveInterpenetration(duration);
}
void Entity::ResolveVelocity(float duration)
{
float separatingVelocity = 0.1f;
if( m_Contact != 0 )
{
// Find the velocity in the direction of the contact
separatingVelocity = CalculateSeparatingVelocity(*m_Contact);
}
// Check if it needs to be resolved
if (separatingVelocity > 0)
{
// The contact is either separating, or stationary - there's
// no impulse required.
return;
}
// Calculate the new separating velocity
float newSepVelocity = -separatingVelocity * m_Restitution;
// Check the velocity build-up due to acceleration only
D3DXVECTOR3 accCausedVelocity = m_LastFrameAcceleration;
if (m_Contact != 0)
{
accCausedVelocity -= m_Contact->GetAcceleration();
}

D3DXVECTOR3 normalThisFrame = m_ContactNormal * duration;
float accCausedSepVelocity = D3DXVec3Dot( &accCausedVelocity, &normalThisFrame );
// If we've got a closing velocity due to acelleration build-up,
// remove it from the new separating velocity
if (accCausedSepVelocity < 0)
{
newSepVelocity += m_Restitution * accCausedSepVelocity;
// Make sure we haven't removed more than was
// there to remove.
if (newSepVelocity < 0)
{
newSepVelocity = 0;
}
}
float deltaVelocity = newSepVelocity - separatingVelocity;
// We apply the change in velocity to each object in proportion to
// their inverse mass (i.e. those with lower inverse mass [higher
// actual mass] get less change in velocity)..
float totalInverseMass = m_InverseMass;
if (m_Contact != 0)
{
totalInverseMass += m_Contact->m_InverseMass;
}
// If all particles have infinite mass, then impulses have no effect
if (totalInverseMass <= 0)
{
return;
}
// Calculate the impulse to apply
float impulse = deltaVelocity / totalInverseMass;
// Find the amount of impulse per unit of inverse mass
D3DXVECTOR3 impulsePerIMass = m_ContactNormal * impulse;
// Apply impulses: they are applied in the direction of the contact,
// and are proportional to the inverse mass.
m_Velocity = ( m_Velocity + impulsePerIMass * m_InverseMass );
if( m_Contact != 0 )
{
// Particle 1 goes in the opposite direction
m_Contact->m_Velocity = ( m_Contact->m_Velocity + impulsePerIMass * -m_Contact->m_InverseMass );
}
}
void Entity::ResolveInterpenetration(float duration)
{
// If we don't have any penetration, skip this step.
if (m_Penetration <= 0)
{
return;
}
// The movement of each object is based on their inverse mass, so
// total that.
float totalInverseMass = m_InverseMass;
if ( m_Contact != 0 )
{
totalInverseMass += m_Contact->m_InverseMass;
}
// If all particles have infinite mass, then we do nothing
if (totalInverseMass <= 0)
{
return;
}
// Find the amount of penetration resolution per unit of inverse mass
D3DXVECTOR3 movePerIMass = m_ContactNormal * (m_Penetration / totalInverseMass);
// Calculate the the movement amounts
m_Movement = movePerIMass * m_InverseMass;
if( m_Contact != 0 )
{
m_Contact->m_Movement = movePerIMass * -m_Contact->m_InverseMass;
}
// Apply the penetration resolution
m_Position = ( m_Position + m_Movement );
if( m_Contact != 0 )
{
m_Contact->SetPosition(m_Contact->m_Position + m_Contact->m_Movement);
}
}
[/CODE]

Really, really appreciate all this help..

Share this post


Link to post
Share on other sites
What's the actual problem you are having? I'm not sure what you expect to have happen differently; you only set m_Contact to non-NULL in a few places, so if that code never executes, m_Contact will never be anything [i]but[/i] NULL.

Share this post


Link to post
Share on other sites
Thanks again ApochPiQ, the thing is that this is a test.. they have give me a non working game that needs to be repair.
I get stuck into this point... everything is working well till the m_Contact is call (that's what show in the watch), then all values comes wrong.
So i was thiniking maybe there is a problem with that value.

Share this post


Link to post
Share on other sites
Heya.. Is it for a position they are having you do this..? I bet they want a measurement of your level, not ours ;)
However - since the internet is a resource you can and should use, I guess it's fine ^^

I suggest you to run the debugger again and take note of where in the application the error occours. Find out in what method etc.

As said earlier the problem is that m_Contant is NULL and trying to call members of a pointer thats pointing to null will cause these errors.
There are a few solutions you could try,
1. make sure m_Contact is never null (as pointed out earlier) when being used
2. make sure that m_Contact is never used if it is null. (as already implemented in many places in the code that you provided (see code below))

[CODE]if (m_Contact != 0)
{
use m_Contact;
}[/CODE]

This makes sure that m_Contact wont be used if it's not assigned. However - be aware - this might not be what you want, the game might expect m_Contact to be assigned and ready to be used at all times and will cause unexpected or unwanted behaviour if not.

So maybe this will point (hehe) you in the right direction. Edited by AlanSmithee

Share this post


Link to post
Share on other sites

This topic is 2054 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this