Jump to content
  • Advertisement
Sign in to follow this  
lincsimp

ODE problems

This topic is 4829 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

Hi I've got the test_friction tutorial to work with "drawstuff" and now I'm trying to remove that from the code. In the simLoop there is this line: dSpaceCollide (space,0,&nearCallback); Which passes a reference for a function to be called if a collision is possible. It compiles, but crashes at this line when I call simLoop. Why is this? cheers

Share this post


Link to post
Share on other sites
Advertisement
Might seem obvious, but are you sure you actually have a space created properly assigned to the Id "space".

Also is the crash inside the callback function? It can go into a lot of recurive functions, any of which could bomb your app.

Share this post


Link to post
Share on other sites
Thanks. I've tried commenting out the callback function and space is a space. I've stripped it down and have changed nothing except:

1. Changed dsSimulationLoop (argc,argv,352,288,&fn); to simLoop(0)
2. Removed drawing functions.


cheers

Share this post


Link to post
Share on other sites
Hmmm well if you post the source then i'd be glad to compare it with a working ODE implementation (if I can dig one out of my code archive) - perhaps something will leap out at me.

Share this post


Link to post
Share on other sites
make sure the ODE binary you are using is compiled using the same runtime library as the executable you are using.

IE if ODE is Multithreaded but your project is Multithreaded Dll, you may get problems. Mixing debug builds and release builds can also sometimes cause odd memory errors.

Personally while developing with Ogre, I've found if I've forgotton to set stuff to multithreaded dll (Ogre's preference) rather then anything else it can screw things up - usually the first sign seems to be std:string behaving unexpectedly.

Though as I said, that's my own personal experience and for all I know the source you've got your hands on is faulty.

Share this post


Link to post
Share on other sites
Thanks very much. Unforunately my host is down, here's the code:

/*************************************************************************
* *
* Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
* All rights reserved. Email: russ@q12.org Web: www.q12.org *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of EITHER: *
* (1) The GNU Lesser General Public License as published by the Free *
* Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. The text of the GNU Lesser *
* General Public License is included with this library in the *
* file LICENSE.TXT. *
* (2) The BSD-style license that is included with this library in *
* the file LICENSE-BSD.TXT. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
* LICENSE.TXT and LICENSE-BSD.TXT for more details. *
* *
*************************************************************************/
#include <ode/ode.h>
#include <iostream>

using namespace std;
// some constants

#define LENGTH 0.2 // box length & width
#define HEIGHT 0.05 // box height
#define MASS 0.2 // mass of box[j] = (i+1) * MASS
#define FORCE 0.05 // force applied to box[j] = (j+1) * FORCE
#define MU 0.5 // the global mu to use
#define GRAVITY 0.5 // the global gravity to use
#define N1 10 // number of different forces to try
#define N2 10 // number of different masses to try


// dynamics and collision objects

static dWorldID world;
static dSpaceID space;
static dBodyID body[N1][N2];
static dJointGroupID contactgroup;
static dGeomID ground;
static dGeomID box[N1][N2];



// this is called by dSpaceCollide when two objects in space are
// potentially colliding.

static void nearCallback (void *data, dGeomID o1, dGeomID o2)
{
int i;

// only collide things with the ground
int g1 = (o1 == ground);
int g2 = (o2 == ground);
if (!(g1 ^ g2)) return;

dBodyID b1 = dGeomGetBody(o1);
dBodyID b2 = dGeomGetBody(o2);

dContact contact[3]; // up to 3 contacts per box
for (i=0; i<3; i++) {
contact.surface.mode = dContactSoftCFM | dContactApprox1;
contact.surface.mu = MU;
contact.surface.soft_cfm = 0.01;
}
if (int numc = dCollide (o1,o2,3,&contact[0].geom,sizeof(dContact))) {
for (i=0; i<numc; i++) {
dJointID c = dJointCreateContact (world,contactgroup,contact+i);
dJointAttach (c,b1,b2);
}
}
}


// start simulation - set viewpoint

static void start()
{
static float xyz[3] = {1.7772,-0.7924,2.7600};
static float hpr[3] = {90.0000,-54.0000,0.0000};
}
static void simLoop (int pause)
{
int i;
if (!pause) {
// apply forces to all bodies
for (i=0; i<N1; i++) {
for (int j=0; j<N2; j++) {
dBodyAddForce (body[j],FORCE*(i+1),0,0);
}
}

dSpaceCollide (space,0,&nearCallback); // problem function
dWorldStep (world,0.05);

// remove all contact joints
dJointGroupEmpty (contactgroup);
}

//dsSetColor (1,0,1);
dReal sides[3] = {LENGTH,LENGTH,HEIGHT};
// update drawing here
}


int main (int argc, char **argv)
{
int i,j;
dMass m;
world = dWorldCreate();
space = dHashSpaceCreate (0);
contactgroup = dJointGroupCreate (0);
dWorldSetGravity (world,0,0,-GRAVITY);
ground = dCreatePlane (space,0,0,1,0);

// bodies
for (i=0; i<N1; i++) {
for (j=0; j<N2; j++) {
body[j] = dBodyCreate (world);
dMassSetBox (&m,1,LENGTH,LENGTH,HEIGHT);
dMassAdjust (&m,MASS*(j+1));
dBodySetMass (body[j],&m);
dBodySetPosition (body[j],i*2*LENGTH,j*2*LENGTH,HEIGHT*0.5);
cout<<"Start position for "<<i<<","<<j<<" = "<<i*2*LENGTH<<","<<j*2*LENGTH<<","<<HEIGHT*0.5<<endl;

box[j] = dCreateBox (space,LENGTH,LENGTH,HEIGHT);
dGeomSetBody (box[j],body[j]);
}
}

// run simulation
//dsSimulationLoop (argc,argv,352,288,&fn);

dJointGroupDestroy (contactgroup);
dSpaceDestroy (space);
dWorldDestroy (world);

simLoop(0);
const dReal* x;
for (i=0; i<N1; i++) {
for (j=0; j<N2; j++) {
x= dBodyGetPosition(body[j]);

cout<<"End position for "<<i<<","<<j<<" = "<<x[0]<<","<<x[1]<<","<<x[2]<<endl;

}
}
cout<<"done"<<endl;
system("PAUSE");
return 0;
}

[\code]

Share this post


Link to post
Share on other sites
Erm...

Quote:
Original post by lincsimp
dSpaceDestroy (space);
dWorldDestroy (world);

simLoop(0);


Put it this way pal, I'd be very worried if it worked ;)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!