【问题标题】:Program runs in visual studio but release executable crashes程序在 Visual Studio 中运行,但释放可执行文件崩溃
【发布时间】:2012-09-16 15:52:42
【问题描述】:

我已经追踪到我写入 txt 文件的时间。我已经检查过它是否已打开,并且它会在崩溃之前向文件写入一行。

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();
}

【问题讨论】:

  • 您能否生成最小的代码示例来重现您的错误并发布它?
  • 我不知道是什么导致这种情况发生,以较小的规模重现它,但这基本上是代码。

标签: c++ visual-studio file exe file-handling


【解决方案1】:

最可能的原因是您在运行发行版时缺少所需的 dll。

在可执行文件上运行 Dependency Walker:http://dependencywalker.com/

【讨论】:

    【解决方案2】:

    您似乎在检查文件是否打开。如果不是,您打印消息“未打开”但仍然继续?

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

    【讨论】:

    • 我只是想追查发生了什么,这只是为了做到这一点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多