Chaitanya
Chaitanya

Reputation: 175

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.

MainWindow.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

#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. 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. The exceptions are thrown even before I enter the MainWindow Constructor. 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. I guess this has something to do with my .exe file but I can't help but wonder why? My .exe file should get a different pointer each time the program is run then why the exception has the exact same location?

Can someone please help me with this problem? I am unable to find any concrete information regarding how to solve this on the internet.

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)

Note: Same question is also posted on Matlab Answers.

Upvotes: 1

Views: 1122

Answers (1)

Chaitanya
Chaitanya

Reputation: 175

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 (i.e. which do not cause application crash) are to be expected when working with Matlab libraries in C++.

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.

Upvotes: 1

Related Questions