I am trying to compile a program that compiles perfectly fine on my desktop but on my laptop, it compiles but gives me this error whenever it is run:
Windows has triggered a breakpoint in RR.exe.
This may be due to a corruption of the heap, which indicates a bug in RR.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while RR.exe has focus.
The output window may have more diagnostic information.
I've commented out lines till I found the line that makes the error which is:
if(glfwOpenWindow(width_, height_, 0, 0, 0, 0, 32, 0, GLFW_WINDOW) != GL_TRUE) {
throw std::runtime_error("Unable to open GLFW window");
}
The weird thing is if I replace width_
and height_
with constants, e.g. 800 and 600 respectively, it stops the heap corruption. Also if I just use the default values set by the constructor instead of passing values it doesn't crash.
Here's the complete code. The above lines are in the Window
constructor.
window.h
#pragma once
#include <iostream>
#include <GL\glew.h>
#include <GL\glfw.h>
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glew32.lib")
#pragma comment(lib, "GLFW.lib")
class Window {
public:
Window(unsigned width = 800, unsigned height = 600);
~Window();
void clear();
inline void display() { glfwSwapBuffers(); }
inline bool exit() { return !glfwGetWindowParam(GLFW_OPENED); }
private:
unsigned width_, height_;
};
window.cpp
#include "window.h"
Window::Window(unsigned width, unsigned height) : width_(width), height_(height) {
if(glfwInit() != GL_TRUE) {
throw std::runtime_error("Unable to initialize GLFW");
}
if(glfwOpenWindow(width_, height_, 0, 0, 0, 0, 32, 0, GLFW_WINDOW) != GL_TRUE) { //crash
//if(glfwOpenWindow(800, 600, 0, 0, 0, 0, 32, 0, GLFW_WINDOW) != GL_TRUE) { //no crash
throw std::runtime_error("Unable to open GLFW window");
}
GLenum result = glewInit();
if(result != GLEW_OK) {
std::stringstream ss;
ss << "Unable to initialize glew: " << glewGetErrorString(result);
throw std::runtime_error(ss.str());
}
}
Window::~Window() {
glfwTerminate();
}
void Window::clear() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
}
main.cpp
#include "window.h"
int main() {
Window wind(1024, 800); //crash
Window wind(800, 600); //crash
Window wind(); //works
return 0;
}
Window wind;
– Phebe