简体   繁体   English

尝试写入 .mat 文件时,在 C++ 中每个构建的完全相同位置抛出异常

[英]Exception thrown at exact same location on each build in C++ when trying to write .mat file

I am trying to write.mat files using C++. I am using Microsoft Visual Studio 2019 along with Qt to develop my application.我正在尝试使用 C++ 编写 .mat 文件。我正在使用 Microsoft Visual Studio 2019 和 Qt 来开发我的应用程序。

MainWindow.h主窗口.h

#include <QtWidgets/QMainWindow>
#include "ui_mainwindow.h"
#include "mat.h"
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget *parent = Q_NULLPTR);
private:
    Ui::MainWindowClass ui;
};

MainWindow.cpp主窗口.cpp

#include "mainwindow.h"
// Following exceptions are thrown even before starting with constructor:
// Exception thrown at 0x00007FFE85813E49 in MatFileTest2.exe: Microsoft C++ exception: mwboost::exception_detail::clone_impl<fl::filesystem::InvalidArgument> at memory location 0x000000BDFB52E410.
// Exception thrown at 0x00007FFE85813E49 in MatFileTest2.exe: Microsoft C++ exception: mwboost::exception_detail::clone_impl<fl::i18n::LcRscOpenFileFailure> at memory location 0x000000BDFB52E1B0.
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    MATFile* myFile = NULL;
    mxArray* myData = NULL;
    mwSize myRow = 1000000;
    mwSize myCol = 1;
   
    myData = mxCreateDoubleMatrix(myRow, myCol, mxREAL); // Line at which below exception is thrown:
    // Exception thrown at 0x00007FFE85813E49 in MatFileTest2.exe: Microsoft C++ exception: foundation::core::except::detail::AnonymousInternalException<foundation::usm::NoActiveContextTypeError> at memory location 0x0000009D6A6FEFB8.
    // This exception complains about .pdb file not being loaded
    
    double* ary = new double[1000000];
    for(int ii = 0; ii < 1000000; ++ii){
        ary[ii] = ii*0.33;
    }
    myFile = matOpen("MATTest.mat", "w");
    mxSetData(myData, ary);
    matPutVariable(myFile, "Sweep_1", myData);
    matClose(myFile);
}

The program is running fine and it is generating the ' MATTest.mat ' file.该程序运行良好,并且正在生成“ MATTest.mat ”文件。 But it keeps on throwing exceptions in the output, but surprisingly none of these exceptions stop the code from running , the program runs fine even with exceptions being thrown.但它一直在抛出异常 output,但令人惊讶的是,这些异常都没有阻止代码运行,即使抛出异常,程序也能正常运行。 The exceptions are thrown even before I enter the MainWindow Constructor.甚至在我进入 MainWindow 构造函数之前就抛出了异常。 The most peculiar thing about these exceptions is that no matter how many times I run the project the location of the exception being thrown doesn't change.这些异常最奇特的是,无论我运行项目多少次,抛出异常的位置都不会改变。 It is always: Exception thrown at 0x00007FFE85813E49 for each exception every single time the project is run.它总是:每次运行项目时,每个异常都会Exception thrown at 0x00007FFE85813E49异常。 I guess this has something to do with my.exe file but I can't help but wonder why?我想这与 my.exe 文件有关,但我不禁想知道为什么? My.exe file should get a different pointer each time the program is run then why the exception has the exact same location?每次程序运行时,My.exe 文件都应获得不同的指针,那么为什么异常具有完全相同的位置?

Can someone please help me with this problem?有人可以帮我解决这个问题吗? I am unable to find any concrete information regarding how to solve this on the inte.net.我无法在 inte.net 上找到有关如何解决此问题的任何具体信息。

My configuration: System: Windows 10 Pro, Version: 2004, OS build: 19041.572 IDE: Microsoft Visual Studio Community 2019, Version 16.7.6 Matlab: R2019a (9.6.0.1072779 (win64)我的配置:系统: Windows 10 Pro,版本:2004,操作系统版本:19041.572 IDE: Microsoft Visual Studio Community 2019,版本 16.7.6 Matlab: R2019a (9.6.0.1072779 (win64)

Note: Same question is also posted on Matlab Answers.注意:同样的问题也发布在 Matlab Answers 上。

After a lot of searching, I found the answer to the following question to "kind of" answer my problem.经过大量搜索,我找到了以下问题的答案,以“某种程度上”回答我的问题。 It basically says that any first chance exceptions (ie which do not cause application crash) are to be expected when working with Matlab libraries in C++.它基本上表示在使用 C++ 中的 Matlab 库时,任何第一次机会异常(即不会导致应用程序崩溃)都是可以预期的。

If anyone has a better explanation or a way to fix this problem, I am still looking for a concrete fix as I do not like even first chance exceptions being thrown in my application.如果有人有更好的解释或解决此问题的方法,我仍在寻找具体的解决方法,因为我什至不喜欢在我的应用程序中抛出第一次机会异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM