PDA

View Full Version : Weird RtlWerpReportException error



Momergil
12th July 2013, 13:46
Hello!

I'm was revising the code of a old software and changing it's scope a little (note: the old version compiled and run perfectly), when I tried to compile and run it and it returned a bizzare error:


Error - RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

I didn't find much about RtlWerpReportException on the web, much less as in my particular situation, so I hope you guys could say what is wrong with my App.

Here is old code and the new code for comparison. As you can see, while there are some significant differences between them, there is no 'special' code that would suggest any kind of error; there is only basic Gui functions and QDir/QFile usage.




//Old main.cpp:

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName("mNote");
app.setApplicationVersion(QString::number(VERSION) );
app.setOrganizationName("Martin");

MainWindow window;

window.show();

return app.exec();
}

//New main.cpp:

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
app.setApplicationName("mNote");
app.setApplicationVersion(QString::number(VERSION) );
app.setOrganizationName("Martinware");
app.setOrganizationDomain("http://www.martinware.com");

MainWindow window;

return app.exec();
}




//Old mainwindow.cpp:

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

//---------------------------- THIS
setWindowIcon(QIcon(":/Images/Images/Sticky_Note.png"));
setWindowTitle("mNote");
setMinimumSize(350,350);

//---------------------------- SETA FLAGS
psrandomalarm = 0; howmuchloops = 0;
Flags.caseChange = false, Flags.entrounominuto = false, Flags.ja_aberto_nesse_dia = false, Flags.leitura_inicial_ocorrendo = false;

//---------------------------- FORM/UI
ui->mainToolBar->setMovable(false);
ui->statusBar->hide();
ui->actionDelete_note->setDisabled(true);
ui->actionDo_this_later->setDisabled(true);
ui->actionOpen_historic->setDisabled(true);

ui->TabWidget->setTabText(0,"Specific");
ui->TabWidget->setTabText(1,"Daily");
ui->TabWidget->setTabText(2,"Memory");
ui->TabWidget->setCurrentIndex(TAB_DAILY);

// Configure action buttons
ui->actionNew_note->setShortcut(Qt::ControlModifier + Qt::Key_N);
ui->actionDelete_note->setShortcut(Qt::ControlModifier + Qt::Key_D);
ui->actionHide->setShortcut(Qt::ControlModifier + Qt::Key_H);
ui->actionDo_this_later->setShortcut(Qt::ControlModifier + Qt::Key_L);

//--------------------------- DEFINE SOURCES DAS NOTAS SALVAS

// Cria diretorio onde as notas ficarão salvas
QDir txtdirectory;
QString v_txtdirectoryname = "./mNote";

if (!txtdirectory.exists(v_txtdirectoryname))
txtdirectory.mkpath(v_txtdirectoryname);


filename_daily = "./mNote/Daily.txt"; //Notas de todos os dias
filename_time = "./mNote/Time.txt"; //Salva quando foi a última vez que o software foi aberto (usado com o Daily)

// Para poder fazer a leitura dos arquivos, é necessário que existam. Se eles não existirem,
// mandar ler vai dar bug; por isso, verifica-se primeiramente se o texto exste.
// Se não existe, se cria um escrevendo vazio ("") nele.

// Define texto 1
{
MReadWrite *mrw = new MReadWrite(this);

if (!mrw->exists(filename_daily))
{
if (!mrw->createFile(filename_daily))
{
QMessageBox::warning(this,"Problem creating Daily text file","A problem occured while trying to create a text file for data storage.\nPlease, go to the folder \"mNote\" and "
"create the text file \"Daily.text\".");
close();
}
}

SAFEDELETE(mrw);
}

//New mainwindow.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"

const QString filenameNotes = QDir::currentPath() + "/mNote/Notes.txt"; //Notas

const QString noteSeparator = ";_;";
const QString itemSeparator = ";;";


MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

//---------------------------- THIS
setWindowIcon(QIcon(":/Images/Images/Sticky_Note.png"));
setWindowTitle("mNote");
setMinimumSize(350,350);

//---------------------------- SETA FLAGS
psRandomAlarm = 0; howMuchLoops = 0;
Flags.entrounominuto =
Flags.ja_aberto_nesse_dia =
Flags.leitura_inicial_ocorrendo = false;

//---------------------------- FORM/UI
ui->mainToolBar->setMovable(false);
ui->statusBar->hide();
ui->actionDelete_note->setDisabled(true);
ui->actionDo_this_later->setDisabled(true);
ui->actionOpen_historic->setDisabled(true);

ui->TabWidget->setTabText(0,"Today");
ui->TabWidget->setTabText(1,"Weekly");
ui->TabWidget->setTabText(2,"For Tomorrow");
ui->TabWidget->setCurrentIndex(TAB_WEAKLY);

// Configure action buttons
ui->actionNew_note->setShortcut(Qt::ControlModifier + Qt::Key_N);
ui->actionDelete_note->setShortcut(Qt::ControlModifier + Qt::Key_D);
ui->actionHide->setShortcut(Qt::ControlModifier + Qt::Key_H);
ui->actionDo_this_later->setShortcut(Qt::ControlModifier + Qt::Key_L);

//--------------------------- DEFINE SOURCES DAS NOTAS SALVAS

// Cria diretorio onde as notas ficarão salvas
QDir txtdirectory;
const QString v_txtdirectoryname = "./mNote";

if (!txtdirectory.exists(v_txtdirectoryname))
txtdirectory.mkpath(v_txtdirectoryname);

// Para poder fazer a leitura dos arquivos, é necessário que existam. Se eles não existirem,
// mandar ler vai dar bug; por isso, verifica-se primeiramente se o texto exste.
// Se não existe, se cria um escrevendo vazio ("") nele.

// Define texto 1
{
QDir dirt;
dirt.setPath(QDir::currentPath() + "/mNote");

if (!dirt.exists() && !dirt.mkdir(dirt.path()))
{
QMessageBox::warning(this,"Error","Failure creating folder \"mNote\", required for the correct usage of this software.\n"
"Go to the installation folder and add this folder so mNote may be used.");
close();
}

MReadWrite *mrw = new MReadWrite(this);

if (!mrw->exists(filenameNotes) && !mrw->createFile(filenameNotes))
{
QMessageBox::warning(this,"Problem creating text file","A problem occured while trying to create a text file for data storage.\nPlease, go to the folder \"mNote\" and "
"create the text file \"Notes.txt\".");
SAFEDELETE(mrw);
close();
}

SAFEDELETE(mrw);
}


Note: MReadWrite is a class for writing to and reading from files. No problem ever shown.

Actually the mainwindow.cpp is bigger than what I'm showing, but it's not necessary to post more, I believe, because I found that the error occurs when the code goes to the SAFEDELETE() function above. The SAFEDELETE() function is a define:



#define SAFEDELETE(_P) if(_P) {delete _P; _P = NULL;}


This function never returned any problems, and as you can see, it was already being used in the old mainwindow.cpp code without errors. MReadWrite could also be the faulty guy, but it's version is the same as the MReadWrite used in the old version and once again there was no errors back then.


I'm glad for any help you could give!!

Momergil

Added after 12 minutes:

Ok, It seems I found the problem: actually MReadWrite did suffer some modifications and I didn't remember. Particulary I added a destructor function that deletes a global QTextStream pointer that in my mNote application wasn't declared yet. So when I commented the "delete qts;", the software could run properly.

The problem now is a new one: in order to avoid that, I added my SAFEDELETE function in the MReadWrite.cpp so it would delete the QTextStream pointer only if it got declared. But instead of doing so, it began to report the same error talked about above. I have no guess why SAFEDELETE() wouldn't work, making my app crash; after all, it verifies if the _P is declared and only then it deletes it.

ChrisW67
13th July 2013, 08:35
You are ensuring that the global QTextStream pointer is initialised to zero at program start aren't you.

Momergil
14th July 2013, 16:43
You are ensuring that the global QTextStream pointer is initialised to zero at program start aren't you.

you mean,



//.h
QTextStream *globalPointer;

//.cpp
constructor
{
globalPointer = NULL;
}


?

Nops. The pointer is only declared when a openRead or openWrite function is called. Is this required for my SAFEDELETE() to work properly?

ChrisW67
11th August 2013, 07:29
I am referring to this:

Ok, It seems I found the problem: actually MReadWrite did suffer some modifications and I didn't remember. Particulary I added a destructor function that deletes a global QTextStream pointer that in my mNote application wasn't declared yet.
If you never initialised the global pointer to zero, never assign to the variable, and then used your macro on it then your program would crash more often than not: you would try to delete some random memory that was never allocated to you. Variables are not initialised by magic.

In your code it makes no sense to create your MReadWrite object on the heap, use, and discard it immediately. You could just put it on the stack and not have to worry about tracking memory at all.