I am using WinApi and playing with codes in my own ways. I have this program with such structures. Here I am creating FCOORD to store floating coordinates value of my (x,y) axis. Next is a circle structure that have center coordinates and radius.
typedef struct _FCOORD{
int x;
int y;
}FCOORD,*PFCOORD;
typedef struct _circle{
float radius;
FCOORD center;
}circle;
In my main() function I have dynamically allocated the memory.
int main(){
int circleCount=0;
float defRad=10.00f;
circle **circ;
circ=(circle **)malloc(sizeof(circle *));
circ[circleCount]=(circle *)malloc(sizeof(circle));
while(1){
if(key[VK_LBUTTON]){
circ[circleCount]->center=GetMouseCoord(); //Here GetMouseCoord() has FCOORD return type
circ[circleCount]->radius=defRad;
//Now I allocate memory for other circle.
circleCount++;
circ[circleCount]=(circle *)malloc(sizeof(circle));
printf("No. of Circles: %d\n",circleCount);
}
/*
* I have functions that display values in Console.
*
*
*/
}
}
Here it works but after about 287 circles the program crashes and shows this error code.
No of Circles : 287
make: *** [run] Error -1073740286
I thought that may be case of stack memory running out so I globalized it to use the heap instead.
circle **circ;
int main(){
/*
*
*/
circ=(circle **)malloc(sizeof(circle *));
circ[circleCount]=(circle *)malloc(sizeof(circle));
/*
*
*/
}
I can now pump out about 673 then it crashes.
No of Circles : 673
make: *** [run] Error -1073741819
Is this problem memory related or is there other things that I have been missing in my code.
ALSO: I found that it usually crashes when I return to the program window after clicking outside when using the globalizing method.
EDIT: Many are saying that this program is just for C, not C++. Well, I am using both codes with winapi and have compiled the whole code with g++. So my whole program is C++ based and only this particular part is code using C. And this error code I don't know if it is from C code part or my other bigger code.
Thanks Sammy1410