Jump to content
  • Advertisement
Sign in to follow this  
walkingcarcass

glut crashing on startup

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

The code below briefly flashes a window before crashing. When I step through it, the glutCreateWindow line in Sketch.cpp crashes with this:
Quote:
Program received signal SIGFPE, Arithmetic exception. 0x002c27a4 in _mesa_test_os_sse_exception_support () from /usr/X11R6/lib/modules/dri/i915_dri.so
and no window pops up. The sequence of glut*() calls is identical to some other code I made as a first attempt. It's messy so I won't post it, but the order of execution of glut*() is the same. Sketch.hpp
class Sketch {
	private:
		// This allows the static callback functions to
		// extract information from the window which
		// owns it.
		static const unsigned int MAX_WINDOWS = 64;
		static Sketch* windows[MAX_WINDOWS];

		static void display_func();
		static void idle_func();
		static void resize_func(int, int);

	// Non-static data.

		unsigned int window_handle;
		unsigned int width, height;
		unsigned int initial_width, initial_height;

	public:
		Sketch(unsigned int, unsigned int, const char*);
		// Width, height, name.

		~Sketch();

		static void init(int* argc, char** argv);
		static void main_loop();
};

Sketch.cpp
Sketch* Sketch::windows[Sketch::MAX_WINDOWS];

void Sketch::init(int* argc, char** argv) {
	glutInit(argc, argv);
}

void Sketch::main_loop(){
	glutMainLoop();
}




Sketch::Sketch(unsigned int w, unsigned int h, const char* name) {
	width = initial_width = w;
	height = initial_height = h;
		
	glutInitWindowSize(width, height);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

	// THIS IS THE LINE THAT CRASHES
	window_handle = glutCreateWindow(name);
	windows[window_handle] = this;

	glutDisplayFunc(&display_func);
	glutIdleFunc(&display_func);
	glutReshapeFunc(&resize_func);

	resize_func(width, height);
}

Sketch::~Sketch() {
	glutDestroyWindow(window_handle);
}


void Sketch::idle_func(){
//	std::cerr << "Idle window " << glutGetWindow() << '\n';
}

void Sketch::resize_func(int new_width, int new_height){
	int window_id = glutGetWindow();
	std::cerr << "Resize window " << window_id << '\n';
	Sketch* sketch = windows[window_id];
		
	if(new_height<=0)
		sketch->height = 1;
	else
		sketch->height = new_height;
	sketch->width = new_width;
	
	glViewport(0, 0, new_width, new_height);
}

	
void Sketch::display_func(){
	Sketch* sketch = windows[glutGetWindow()];
		
	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,sketch->width,0,sketch->height,-1.0,1.0);
		
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glClearColor(0,1.0,0,0);
	glClear(GL_COLOR_BUFFER_BIT);
		
	float max = 30;
	float min = 40;
		
	glColor3f(1.0,1.0,1.0);
	glBegin(GL_QUADS);
	// Draw the centre square.
	glVertex2f(min,min);
	glVertex2f(min,max);
	glVertex2f(max,max);
	glVertex2f(max,min);
	glEnd();
		
	glutSwapBuffers();
}

main.cpp
#include "Sketch.hpp"

int main(int argc, char** argv){
	UI::Sketch::init(&argc, argv);
	UI::Sketch(300,100,"abc");
	UI::Sketch::main_loop();
	return 0;
}

Share this post


Link to post
Share on other sites
Advertisement
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!