嗨,我有一个奇怪的问题,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 扭曲该范围,我可以在自己的代码中捕获此异常)
更新:尝试将两个局部变量从堆栈移动到堆(使用新的)并且问题仍然存在。