Acces violation at newtonUpdate

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Acces violation at newtonUpdate

Postby FSA » Fri Aug 02, 2013 3:03 pm

Why does Newton crash on NewtonUpdate when I have set an own ForceAndTorque function? My code is the following:

Code: Select all
class Foo
{
private:
        virtual void    PhysicBodyCallbackIntern(const NewtonBody* body, dFloat timestep, int threadIndex);
public:
    typedef void(Foo::*CallbackFunc)(const NewtonBody*, dFloat, int);
 
        //...
};
 
Foo::Init()
{
    Foo::CallbackFunc pCallB = &Foo::PhysicBodyCallbackIntern;
    NewtonBodySetForceAndTorqueCallback(m_pPhysicBody, (NewtonApplyForceAndTorque)&pCallB);
}

pCallb is not NULL. The Body is created.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am

Re: Acces violation at newtonUpdate

Postby Julio Jerez » Fri Aug 02, 2013 3:13 pm

Code: Select all
private:
        virtual void    PhysicBodyCallbackIntern(const NewtonBody* body, dFloat timestep, int threadIndex);
};

PhysicBodyCallbackIntern must be a static function

here is an exampel of hwo to set that up, from the dNewton class
Code: Select all
class dNewtonDynamicBody: public dNewtonBody
{
   public:
   CNEWTON_API dNewtonDynamicBody(dNewton* const world)
                 {
                   ....
         NewtonBodySetForceAndTorqueCallback(m_body, OnForceAndTorque);
                 }
   CNEWTON_API virtual ~dNewtonDynamicBody();

   CNEWTON_API virtual void OnForceAndTorque (dFloat timestep, int threadIndex) = 0;
   private:
   CNEWTON_API static void OnForceAndTorque (const NewtonBody* body, dFloat timestep, int threadIndex)
                {
                   dNewtonDynamicBody* const me = (dNewtonDynamicBody*) NewtonBodyGetUserData(body);
           dAssert (me);
          me->OnForceAndTorque (timestep, threadIndex);
                }
};
Julio Jerez
Moderator
Moderator
 
Posts: 12478
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Acces violation at newtonUpdate

Postby FSA » Sun Aug 04, 2013 10:56 am

Ah thank you! Works now.
User avatar
FSA
 
Posts: 322
Joined: Wed Dec 21, 2011 9:47 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron