簡體   English   中英

C ++向量構造函數引發std :: out_of_range異常(Microsoft C ++ stdlib)

[英]C++ vector constructor throws std::out_of_range exception (Microsoft C++ stdlib)

嗨,我有一個奇怪的問題,即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中使用VisualStudio2008。如何解決此問題的任何想法? 謝謝。

更新:是的,這是第一次機會異常,但未在STL中處理,而是直接彈出來使我的應用程序崩潰。 (如果我使用try-catch扭曲該范圍,則可以在自己的代碼中捕獲此異常)

更新:試圖將兩個局部變量從堆棧移動到堆(使用new),問題仍然存在。

通過在調試器和其他各種輔助工具(如應用程序驗證程序)中使用“斷點續傳”選項,我終於發現,一些編譯器優化使Visual Studio調試器更上一層樓。 在兩個變量聲明之間執行在同一范圍內的函數調用。 因此,在Visual Studio調試器中,突出顯示的行是std :: vector“ Point3”法線; 然后按F10鍵並引發異常,該F10步驟執行的實際代碼不是突出顯示的那一行。

更糟糕的是,該函數調用被重定向到一個我沒有調試符號的外部DLL,並且異常來自該DLL。 因此,調試器中捕獲的調用堆棧也已損壞。

我使用的是Intel C ++編譯器,並且使用調試版本時,所有優化選項均已關閉。 但是該范圍內的代碼執行順序仍然無法完全證實Visual Studio的想法。 這里的方法僅僅是注釋掉所有可能引發異常並逐一取消注釋的事物。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM