0

嗨,我有一个奇怪的问题,std::vector<> 的构造函数抛出了 out_of_range 异常。异常如下所示:

First-chance exception at 0x000007fefde09e5d in 3dsmax.exe: Microsoft C++ exception: std::out_of_range at memory location 0x6726ee40..

无论如何,这不是很有帮助。在调试器中,代码如下:

std::vector<Point3> points;
std::vector<Point3> normals;

例外来自第二行。这是两个局部变量,意味着它们在一个成员函数体中,并且被多次调用。首次调用这两个构造函数时不会发生异常,但总是在第二次命中第二行(法线)时抛出异常。“Point3”类在 3dsmax SDK 中定义,如下所示:

class GEOMEXPORT Point3: public MaxHeapOperators {

public:
float x,y,z;

// Constructors
/*! \remarks Constructor. No initialization is performed. */
Point3() { /* NO INIT */ }
/*! \remarks Constructor. x, y, and z are initialized to the values specified. */
Point3(float X, float Y, float Z)  { 
     x = X; y = Y; z = Z; 
 }
/*! \remarks Constructor. x, y, and z are initialized to the specified values (cast as floats). */
Point3(double X, double Y, double Z) { 
     x = (float)X; y = (float)Y; z = (float)Z; 
 }
/*! \remarks Constructor. x, y, and z are initialized to the specified values (cast as floats). */
Point3(int X, int Y, int Z) { 
     x = (float)X; y = (float)Y; z = (float)Z; 
 }
/*! \remarks Constructor. x, y, and z are initialized to the specified Point3. */
Point3(const Point3& a) { 
     x = a.x; y = a.y; z = a.z; 
 } 

你可以在 3ds max sdk 的 Point3.h 中找到这个类。它里面只有 3 个浮点数,并且似乎有足够的各种类型的构造函数。我不敢相信这堂课有问题。

我在 Windows 7 中使用 VisualStudio 2008。知道如何解决这个问题吗?谢谢。

更新:是的,这是第一次机会异常,但它没有在 STL 中处理并直接弹出以使我的应用程序崩溃。(如果我使用 try-catch 扭曲该范围,我可以在自己的代码中捕获此异常)

更新:尝试将两个局部变量从堆栈移动到堆(使用新的)并且问题仍然存在。

4

1 回答 1

0

通过在调试器和其他各种辅助工具(如应用程序验证器)中使用 break on throws 选项,我终于发现一些编译器优化会向上滚动 Visual Studio 调试器。在两个变量声明之间执行位于同一范围内的函数调用。因此,在 Visual Studio 调试器中,突出显示的行是std::vector"Point3" 法线;我按下 F10 并引发异常,在 F10 步骤执行的实际代码不是突出显示的那一行。

更糟糕的是函数调用重定向到我没有调试符号的外部 DLL,异常来自该 DLL。因此,调试器中捕获的调用堆栈也被破坏了。

我使用的是英特尔 C++ 编译器,在调试版本中,所有优化选项都已关闭。但是该范围内的代码执行顺序仍然不能完全符合 Visual Studio 的想法。这里的方法只是注释掉所有可能引发异常的东西,并一一取消注释。

于 2013-02-22T23:33:18.403 回答