2012-09-16 30 views
2

我已經將它跟蹤到了當我正在寫入一個txt文件。我已檢查它是否打開,並在文件崩潰之前將文件寫入該文件。程序在Visual Studio中運行,但發佈可執行程序崩潰

VS2012外部調試器會拋出此Unhandled exception at 0x77112D24 (ntdll.dll) in DTC.exe: 0xC0000005: Access violation writing location 0x10000000,並指向fstream頭中的此函數virtual __CLR_OR_THIS_CALL ~basic_filebuf()

void main() 
{ 
    vector<string> fileNames; 
    vector<time_t> fileTimes; 

    CImg<unsigned char> image("Image.bmp"); 

    ofstream out("Result_Data.txt",ios::out|ios::app); 
    if(!out.is_open()) 
    { 
     cout<<"File Not Opened!\n"; 
    } 
    unsigned long originalSize = my_image_functions::getFileSize("Image.bmp"); 
    time_t before = 0, after = 0; 

    before=clock(); 
    my_image_functions::compressDualLevelBTC(image,"dualBTC_2_8.dtc",2,8); 
    after = clock(); 

    fileTimes.push_back(after-before); 
    fileNames.push_back("dualBTC_2_8.dtc"); 

    //... 
    /* Several of these segments*/ 
    //... 


    before=clock(); 
    my_image_functions::compressDualLevelBTC(image,"dualBTC_32_64.dtc",32,64); 
    after = clock(); 

    fileTimes.push_back(after-before); 
    fileNames.push_back("dualBTC_32_64.dtc"); 

    while(!fileNames.empty() && !fileTimes.empty()) 
    { 
     out<< fileNames.back() <<";"<< fileTimes.back() <<";"<< my_image_functions::getFileSize(fileNames.back()) << ";" << ((float) originalSize)/my_image_functions::getFileSize(fileNames.back()) << endl; 
     fileNames.pop_back(); 
     fileTimes.pop_back(); 
     if(!out.is_open()) 
     { 
      cout<<"File Not Opened!\n"; 
     } 
    } 
    out.close(); 
} 
+4

您能否生成再現錯誤並將其發佈的最小代碼示例? – chris

+0

我不知道是什麼原因導致這種情況發生在較小的範圍內,但這基本上是代碼。 – jrl

回答

1

最有可能的原因是您在運行發行版時缺少所需的dll。

運行的Dependency Walker上的可執行:http://dependencywalker.com/

0

你似乎來檢查文件是打開與否。如果不是,則打印消息「未打開」,但繼續進行?

ofstream out("Result_Data.txt",ios::out|ios::app); 
if(!out.is_open()) 
{ 
    cout<<"File Not Opened!\n"; 
} 
+0

我只是想找出發生了什麼,這只是拋出在那裏做。 – jrl

相關問題