PDA

View Full Version : Release mode issue



regular
24th April 2013, 17:28
Hi

I have an application that builds and runs fine in Debug mode, but when ran in Release mode it produces a "Access violation reading location 0x...." error. I try to process the command line parameters passed to the application before constructing the QMainWindow and calling QApplication.exec(). I have put some qDebug() statements and it appears it crashes straight after I call any QString methods. It appears to me that there might be some linking errors but I can't seem to find the cause. Here's my main() function:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWindow *mw= 0;
QString s = QString("myHardCodedString").toLower().trimmed();
qDebug() << s;
if(a.argc() > 1)
{
qDebug() <<"before check";
QString correctStr = MyHelper::getProgramStr();
qDebug() <<"str: " << correctStr;

qDebug() << a.arguments();
qDebug() << a.arguments().at(1);

QString res = a.arguments().at(1).toLower().trimmed();
qDebug() << "arg: " << res;

//code below never reached in Release mode
//..........
}
else
{
QErrorMessage *error = new QErrorMessage();
//set errormessage
//.........
}

return a.exec();
}

The last qDebug() message before the "Access violation" error in release mode is this one:

qDebug() << a.arguments().at(1);

A note: I put the "myHardCodedString" string just to test if the problem was caused by QString methods. Before I put that in, the error surfaced later on in the main function, but with it there, the error occurred right after the stated qDebug() line and before the next one.

I am using Qt 4.8.3 on Windows 7 x64 and VisualStudio 2010.

Hope that's enough information and thanks in advance.

Santosh Reddy
24th April 2013, 18:10
Just clean build the application and make sure you are using correct version of release mode dlls when running in the release mode

regular
25th April 2013, 11:03
Thanks for the response.

However, I have tried clean building the solution and it is using the correct dlls (the correct Qt version and not the debug mode ones) but it still produces the same error.

Added after 47 minutes:

Additional information:

I produced debug information for the release build and after running it, the error appears to happen at the QList<T>::free() function:


// ### Qt 5: rename freeData() to avoid confusion with std::free()
template <typename T>
Q_OUTOFLINE_TEMPLATE void QList<T>::free(QListData::Data *data)
{
node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
reinterpret_cast<Node *>(data->array + data->end));
qFree(data);
}

Line 7 is where the debugger reports the exception. The QList is of type QList<QString> *const, it has more than 11 million elements and the free() function is called from this line in my own code:


QString res = a.arguments().at(1).toLower().trimmed();

Added after 16 minutes:

Another update:

I have another project in the same solution that has the same problem (except the main window shows and the exception happens when a button is pressed) and after running its release mode build through the debugger I can see that the this pointer (for my QMainWIndow) is set to NULL in the button's SLOT. Again, this only happens in release mode.

amleto
27th April 2013, 12:49
please show the output from this


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWindow *mw= 0;
QString s = QString("myHardCodedString").toLower().trimmed();
qDebug() << s;
if(a.argc() > 1)
{
qDebug() <<"before check";
QString correctStr = MyHelper::getProgramStr();
qDebug() <<"str: " << correctStr;

qDebug() << a.arguments();
qDebug() << a.arguments();

qDebug() << a.arguments().at(1);
qDebug() << a.arguments().at(1);
}

}




However, I have tried clean building the solution and it is using the correct dlls (the correct Qt version and not the debug mode ones) but it still produces the same error.
please show some proof for this. the command line call for the compiler + linker should be sufficient.

Do you have different versions of Qt installed?

You needn't waste time debugging Qt code. what you are seeing is not a Qt bug.

regular
29th April 2013, 11:01
Hi,

Sorry for the late reply. The problem was fixed when I turned the compiler optimization off in release mode. However, I still don't know where the issue is and would rather find it and fix it itself isntead of turning optimization off. I ran this code (slightly modified of yours, added the trimmed() function):

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWindow *mw= 0;
QString s = QString("myHardCodedString").toLower().trimmed();
qDebug() << s;
if(a.argc() > 1)
{
qDebug() <<"before check";
QString correctStr = MyHelper::getProgramStr();
qDebug() <<"str: " << correctStr;

qDebug() << a.arguments();
qDebug() << a.arguments();

qDebug() << a.arguments().at(1);
qDebug() << a.arguments().at(1).trimmed();
}

}
And here's the output (there is no error when I remove the trimmed() function):

"myhardcodedstring"
before check
str: "5F7141C1DA10FA56A55810589CCD20F94E5B565B"
("C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.exe", "020076EA5F473EC798FF4B6407DBE337B33084B1", "C:\Users\andreyu\Desktop\options.xml")
("C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.exe", "020076EA5F473EC798FF4B6407DBE337B33084B1", "C:\Users\andreyu\Desktop\options.xml")
"020076EA5F473EC798FF4B6407DBE337B33084B1"
First-chance exception at 0x00000029 in MyApp.exe: 0xC0000005: Access violation.
Unhandled exception at 0x770915de in MyApp.exe: 0xC0000005: Access violation.


This happens when I turn optimization on, when it's off it all works fine.

Here's the command line options for compiler:

/I".\GeneratedFiles" /I"." /I"C:\Qt\4.8.3\include" /I".\GeneratedFiles\Release" /I"C:\Qt\4.8.3\include\QtCore" /I"C:\Qt\4.8.3\include\QtGui" /I"C:\Qt\4.8.3\include\QtXml" /I"C:\Qt\kdsoap\include" /I"C:\Qt\4.8.3\include\QtXmlPatterns" /nologo /W1 /WX- /Ox /Oy- /D "UNICODE" /D "WIN32" /D "QT_LARGEFILE_SUPPORT" /D "QT_DLL" /D "QT_NO_DEBUG" /D "NDEBUG" /D "QT_CORE_LIB" /D "QT_GUI_LIB" /D "QT_XML_LIB" /D "QT_XMLPATTERNS_LIB" /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t- /Zc:forScope /Fp"Release\MyApp.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue
and linker:

/OUT:"C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\\MyApp.exe" /NOLOGO /LIBPATH:"C:\Qt\kdsoap\lib" /LIBPATH:"C:\Qt\4.8.3\lib" "qtmain.lib" "QtCore4.lib" "QtGui4.lib" "QtXml4.lib" "kdsoap1.lib" "QtXmlPatterns4.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Release\MyApp.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.pdb" /SUBSYSTEM:WINDOWS /PGD:"C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

And yes, I have Qt 4.8.3 and Qt 4.8.2_x64 installed.

amleto
29th April 2013, 15:26
I bet if you uninstall the x64 version and make sure all files are removed, then the problem will 'go away'.