建設與Visual Studio 2017年一個項目,我遇到了這個錯誤退出:的Visual Studio 2017年 - 錯誤MSB6006: 「CL.EXE」 與代碼2
error MSB6006: "CL.exe" exited with code 2.
這裏是我的代碼:
int main()
{
const int WIDTH=800;
const int HEIGHT=600;
Bitmap bitmap(WIDTH, HEIGHT);
unique_ptr<int[]> histogram(new int[Mandelbrot::MAX_ITERATIONS + 1]{ 0 });
unique_ptr<int[]> fractal(new int[WIDTH*HEIGHT]{ 0 });
//int fractal[WIDTH*HEIGHT]{ 0 };
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
double xFractal = (x - WIDTH/2 - 200)*2.0/HEIGHT;
double yFractal = (y - HEIGHT/2)*2.0/HEIGHT;
int iterations = Mandelbrot::getIterations(xFractal, yFractal);
if (iterations != Mandelbrot::MAX_ITERATIONS) {
histogram[iterations]++;
}
fractal[y*WIDTH + x] = iterations;
uint8_t color = 256 * (double)iterations/Mandelbrot::MAX_ITERATIONS;
color = color*color*color;
bitmap.setPixels(x, y, color, color, color);
}
}
bitmap.write("Mandelbrot.bmp");
return 0;
}
的問題似乎是分形陣列的聲明:
unique_ptr<int[]> fractal(new int[WIDTH*HEIGHT]{ 0 });
,如果我是(和評論其他線路與分形變量)的代碼編譯就好了,如果我將獨特指針更改爲普通的int數組,代碼將編譯,但是當我調試它時,會引發異常,表示出現堆棧溢出。
減小數組的大小解決了問題,所以看起來程序沒有足夠的內存空間來運行。我GOOGLE了很多,發現visual studio限制堆棧大小爲1MB的deafult(我可能是錯誤的),但我無法找到如何在Visual Studio 2017手動增加它。有人可以幫助我嗎?
編輯:這裏是完整的輸出:
1>------ Build started: Project: Fractal, Configuration: Debug Win32 ------
1>Main.cpp 1>INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\VC\Tools\MSVC\14.11.25503\bin\HostX86\x86\CL.exe'
1> Please choose the Technical Support command on the Visual C++ 1>
Help menu, or open the Technical Support help file for more
information 1>C:\Program Files (x86)\Microsoft Visual
Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(360,5):
error MSB6006: "CL.exe" exited with code 2. 1>Done building project
"Fractal.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
題外話:我很困惑,爲什麼你使用'的unique_ptr的''不是的std ::矢量'(或'的std ::數組「,因爲你的大小可以編譯時間常量) –
UnholySheep
你向我們展示的錯誤的行是最少的信息。請將* full *和* complete *錯誤消息複製粘貼到問題主體中。 –
使用完整的錯誤消息進行編輯。我仍然是一名初學者,我正在學習一門課程,老實說,我使用了獨特的指針,因爲他們在課程中使用過。我剛剛嘗試使用向量,它的工作原理,而數組引發此異常:「在Fractal.exe 0x01393089未處理的異常:0xC00000FD:堆棧溢出(參數:0x00000000,0x00482000)。我現在很困惑,爲什麼這個矢量工作? –