我試圖編譯編譯我的桌面上,但我的筆記本電腦,它編譯,但給我只要運行這個錯誤完全正常的程序編譯:堆損壞,但只有當筆記本電腦
Windows有在RR.exe中觸發了一個斷點。
這可能是由於堆損壞導致RR.exe或其中已加載的任何DLL文件存在bug。
這也可能是由於用戶在RR.exe有焦點時按下F12。
輸出窗口可能有更多診斷信息。
我註釋掉線,直到我發現,使這是錯誤的行:
if(glfwOpenWindow(width_, height_, 0, 0, 0, 0, 32, 0, GLFW_WINDOW) != GL_TRUE) {
throw std::runtime_error("Unable to open GLFW window");
}
奇怪的是,如果我更換width_
和height_
與常量,例如800和600,它會停止堆損壞。另外,如果我只是使用由構造函數設置的默認值而不是傳遞值,它不會崩潰。
下面是完整的代碼。以上幾行代碼都在Window
構造函數中。
在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;
}
+1用於提供一個完整的,相對短的測試情況。 – 2012-03-19 11:46:26
你有你保證在兩臺機器上都有完全相同版本的系統/運行時DLL? – 2012-03-19 11:47:28
它們是完全相同的DLL,.libs和pro因爲我將它們放在保管箱中。 – Lerp 2012-03-19 11:50:17