我试图编译编译我的桌面上,但我的笔记本电脑,它编译,但给我只要运行这个错误完全正常的程序编译:堆损坏,但只有当笔记本电脑
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