Original Post
Im trying to write a physics simulation that simulates the result of various forces on particles, and in the latest version, it has been displaying the runtime error: Unhandled exception at 0x6c18320f in CoordinatesTest.exe: 0xC0000005: Access violation reading location 0x00000053. I tried just moving all of the graphics code out of the source file and running it, just displaying certain states of the particles, but it continued to display this message. I'm not incredibly experienced, so this may or may not be a simple problem, but any help is much appreciated. #include #include #include #define NUM_PARTICLES 9 #define EARTH_MASS 5.9742E+24 #define AU 149598000//kilometers #define GC 6.0E-14//pow(kilometer,3)/kg * pow(s, 2) #define PI 3.14159265358979323846264338327950 char names[NUM_PARTICLES] = {'S', 'M', 'V', 'E', 'm', 'J', 'S', 'U', 'N'}; double Points[NUM_PARTICLES][3]; double Velocities[NUM_PARTICLES][NUM_PARTICLES-1][3]; double finalVelocities[NUM_PARTICLES][3]; double force[3]={0.0, -9.8, 0.0};// force due to Earth's gravity double distances[NUM_PARTICLES][NUM_PARTICLES-1];//array of the distances between particles, first element is between first and second particle etc. double pGrav[NUM_PARTICLES][NUM_PARTICLES-1];//array of the gravity force between particles using distances[] to calculate it, and storing in the same manner double radius[NUM_PARTICLES] = {0.00 * AU, 0.39 * AU, 0.72 * AU, 1.00 * AU, 1.52 * AU, 5.20 * AU, 9.54 * AU, 19.22 * AU, 30.06 * AU}; double orbitalAngles[NUM_PARTICLES] = {0.00, 3.38, 3.86, 7.25, 5.65, 6.09, 5.51, 6.48, 6.43}; double elevation[NUM_PARTICLES]; double mass[NUM_PARTICLES] = {3329146 * EARTH_MASS,0.055 *EARTH_MASS, 0.815 * EARTH_MASS, 1.0 * EARTH_MASS, 0.107 * EARTH_MASS, 317.8 *EARTH_MASS, 95.152 * EARTH_MASS, 14.536 * EARTH_MASS, 17.147 * EARTH_MASS};//mass of the planets as multiples if Earth double time_step = 0.01; double time = 0.0; int x; double Elevation(double angle, double radius){ return (sin(angle*(PI/180)) * radius); } //3d distance formula double distance(double x1, double y1, double z1, double x2, double y2, double z2){ double a, b, c, d = 0; a = pow(x1 - x2,2); b = pow(y1 - y2, 2); c = pow(z1 - z2, 2); d = sqrt(a + b + c); return(d); } double particleGravity(double mass1, double mass2, double distance){ double m, f = 0.00000000006; m = mass1 * mass2; f = GC * (m/pow(distance, 2)); return (f); } void tempDistance(void){ int i, m; double d, g; for(i = 0; i[0], Points[1], Points[2], Points[m][0], Points[m][1], Points[m][2]); distances[m] = d; g = particleGravity(mass, mass[m], distances[m]); pGrav[m] = g; } } } //acceleration is dv/dt Calculation, dv/dt = F/m, Right now this is using the constant for the Earth's gravity double accel (double mass, double force){ mass = 1.0; return force/mass; } //gravity between particles calculation void initialPoints(void){ int i; for(i=0;i[0] = radius; Points[1] = 0; Points[2] = Elevation(orbitalAngles, radius); finalVelocities[0]=20.0; finalVelocities[1]=10.0; finalVelocities[2]=0.0; } time = 0.0; } int main(){ int i, m; initialPoints(); tempDistance(); //a study of earth for(m = 0;m<1;m++){ printf("%s.mass = %f\n",names[m], mass[m]); printf("%s.orbitalRadius = %f\n",names[m], radius[m]); printf("%s.orbitalAngle = %f\n", names[m], orbitalAngles[m]); printf("%s.elevation = %f AU\n",names[m], (Points[m][2]/AU)); printf("%s.position = %f AU %f AU %f AU\n",names[m], Points[m][0]/AU, Points[m][1]/AU, Points[m][2]/AU); for(i=0;i/AU); } for(i=0;i); } } return(0); }