C++ bad_alloc 在内存位置异常

标签 c++ visual-studio-2010 opengl openscenegraph

Unhandled exception at 0x758cd36f in OSGP.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0028ef70..

我正在尝试在 Visual Studio 中执行以下代码。但是,我一直遇到上面的异常。我添加了一个 try catch 来帮助我捕获错误,但似乎无济于事。我认为问题与输出窗口中的以下内容有关

First-chance exception at 0x758cd36f in OSGP.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0019f2f4..
First-chance exception at 0x758cd36f in OSGP.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0019ec84..
First-chance exception at 0x758cd36f in OSGP.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..
The thread 'Win32 Thread' (0x16dc) has exited with code 0 (0x0).
The program '[448] OSGP.exe: Native' has exited with code 0 (0x0).**

代码如下:

#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <new>

#include "stdafx.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{ 
    int flag = false;
    osgViewer::Viewer viewer;
     osg::ref_ptr<osg::Node> root;
    try
    { 
        root = osgDB::readNodeFile("cessna.osg");
        viewer.setSceneData(root.get()); 
    }
    catch(bad_alloc)
    { 
        if (flag) cout << "a bad_alloc exception just occured"; 
    }
    return viewer.run(); 
}

最佳答案

std::bad_alloc 通常在程序没有足够的内存来完成请求的操作时抛出。

可能出现的问题:

  • cessna.org 太大,无法在您运行的机器上处理 这在
  • cessna.org 中的错误数据/逻辑导致它尝试分配 无限量的内存

但根据给定的信息,这不可能说。

关于C++ bad_alloc 在内存位置异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10940067/

相关文章:

c++ - Visual Studio C++ 2008/2010 - 浮点 NaN 中断

opengl - 在网络中使用 openGL 的最佳方法是什么?

opengl - 计算着色器中的 imageStore 到深度纹理

c++ - OpenGL 1.x 显示带有纹理的 GL_QUADS,纯色不

c++ - 链接 vc6 dll/lib 时未解析的符号

c++ - 我不明白 sizeof() 和数组给出的值

C++在派生类中将默认参数更改为构造函数

c++ - 在 C++ 中,If 语句后跟分号而不是大括号是什么意思?

c# - Visual Studio 2010 程序集引用问题

c++ - 我们可以使用 `LoadLibrary ` 让我们的应用程序使用 Visual Studio 2010 和静态运行时编译吗?