[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 149 KB, 1000x500, 1314093901721.png [View same] [iqdb] [saucenao] [google]
4722728 No.4722728 [Reply] [Original]

Ok, I've just about had enough. I'm writing a soft-body simulation in C++ with Opengl and glut. First problem I have is an apparently random "corruption of the heap" if I for instance wanted to change the number of points in a body. Here is some code.

class Point
{
public:
float x,y;
float bx,by;
float InvMass;
float vx,vy;
float bvx,bvy;
float dx,dy;
Point();
Point(int, int );
Point(int, int,float );
};
class Body
{
public:
Point* PointCloud;
Constraint* Constraints;
//Other unimportant things
}

int P=35;
int D=25;
int Ds=(float)sqrt((double)D);
int S=4;

Body Scen0Bodies[MAX_BODIES]=
{Body(D,2*Ds*(Ds-1)+(Ds-1)*(Ds-1)*2,4*(4((Ds1))-4)),
Body(4,6),Body(4,4),Body(P+2,15*(P+2-1)/2,(P+2-1)*2)};


The problem I have here is that I get the "corrupted heap" error if I try to set a P greater than 35. If I lower D to 16 I can add another 2 onto P however for D=9 every value of P will trigger corrupted heap. I'm not too informed on pointers so there might be some size limitations I am overlooking.

Another problem, probably related to this is that my simulation randomly and abruptly changes the values of a certain object's attributes to something insane leading to an unstable simulation; This problem is probably related to the above in some way, either directly or through my lack of programming skill.

I will post the full compile-able source if any brave soul wishes to dive into it.

>> No.4722730

Yeah, let /g/ have all the [code] tags.

>> No.4722738

>class

Stopped reading here. OOP is the cancer that is killing CS.

>> No.4722750

>>4722728
class Body{}; // semicolon missing

int Ds=(float)sqrt((double)D); // WTF is this casting shit? int Ds = (int) sqrt((float)D);

// MAX_BODIES is 4?

// There is no constructor defined on Body

Body(D,2*Ds*(Ds-1)+(Ds-1)*(Ds-1)*2,4*(4((Ds1))-4))


Also post this on stackoverflow

>> No.4722757

>>4722728
wow. now i know what happens when scientists try to write computer programs.
this is fucking unreadable

>> No.4722760

Stacktrace dat shit.

>> No.4722761

>>4722738
no

>> No.4722772

>>4722750
>>semicolon missing
It's there in my source, must have pasted wrong.

>>Max bodies
Is 100; I've tried many values but it seems to have no immediate effect.

>>no Constructor for body.
I have four constructors for body, I didn't post them to shorten clutter and because I doubt the problem is there.

>>stackoverflow
Will do

>>4722757
Yes, my eyes bleed every time I look at my code; I'm hoping that when I get round to cleaning it up it will look a bit nicer.

>>4722760
I've tried some elementary stacktracing but I uncovered nothing, I'll probably end up doing this anyway.

>> No.4722775

>>4722772
the #1 thing you should do right now is CLEAN UP THE CODE
not only will you probably find what is happening, but you will also be able to have other people read it and critique.

>> No.4722782

>>4722775

You're absolutely right, I would say the same thing to myself but I've been putting it off as I will have to rewrite the entire goddamn thing anyway when I'm writing up the theoretical part of my work.

>> No.4722800

do it in matlab