Runtime Exception while populating stl vector from inside GlutCallBack functions


I have a struct Point with two values X and Y to save the value mouse click positions.

struct Point
	int x, y;
	Point(int a, int b)
		x = a;
		y = b;

And I have this global declaration of vector

vector<Point> P;

So when I use this vector to populate random points in functions that are called from main() and not glutcallbacks it works fine.

But when I use the same globally declared vector to populate random points in glutCallBack functions like glutDisplayFunc or glutMouseFunc it compiles but gives me an Unhandled Exception Error

void display(void)
		P.push_back(Point(currentX, currentY));
	int i;
	for (i = 0; i <= ImageH/2; i++) 
		setFramebuffer(i, i, 0, 1.0, 1.0);


When I break the exception from VS, it takes me to std::vector header to a location


I’m not sure if I’m missing anything. Any help would be greatly appreciated. Thanks in advance! :slight_smile: