PDA

View Full Version : QList: Out of Memory Error



ignoramous
15th May 2009, 05:50
I've been trying to work around this runtime mayhem for past 24 with no avail.
I'm a beginner, and have no knowledge about the inbuilt debugger in Qt4. I've tried to run the program sans the Qt GUI, and it works fine.

I've narrowed down the OOM killer to a function getWildCards(word); But I'm not sure what wrong I'm doing in there and moreover I'm not using QList anywhere in the entire program to get that error.

Qt exits the program with a "Microsoft Visual C++ Runtime Error" and a code 3.

Here's the code snippet.


void MainWindow::spellCheck() { //a private slot
QByteArray qB = ui->lineEditWord->text().toLatin1();
char* word = (char *) qB.data(); //casts QByteArray to char*
QString string;

ui->txtEditMain->insertPlainText(" ");
ui->txtEditMain->insertPlainText(ui->lineEditWord->text());

ui->txtEditSpell->setText(QString::null);

WDict->spellcheck(word,2); //calls a spellchecker, WDict is a private *member
for(int i=0; i<WDict->sw.ubound; i++) { //WDict->sw.ubound is upper bound for the iteration
string = (QString(QLatin1String(WDict->sw.valid_words[i])).toLower());
if(string.isEmpty()!=true)
ui->txtEditSpell->append(string);
string.clear();
}
ui->lblSpell->setText(QString::number(WDict->sw.ubound).append(" Spellings"));

ui->txtEditWild->setText(QString::null);
ui->lineEditWord->setText(QString::null);
getWildcards(word); //<--------the problem occurs when this function is called
}

void MainWindow::getWildcards(char* word) { //the problematic function!
QString string2;

WDict->trie_wildcard_print(word); //calls a function which works perfectly fine
for(int i=0; i<WDict->sw.ubound; i++) { //on an average ubound is about 300
string2 = QString(QLatin1String(WDict->sw.valid_words[i])); //valid_words is 600long and 64wide
string2.toLower();
ui->txtEditWild->append(string2);
string2.clear();
}
ui->lblWild->setText(QString::number(WDict->sw.ubound).append(" Wild Cards"));
}



Merci en avance.

jano_alex_es
15th May 2009, 07:53
If I were you, I'd debug the application and search where and when your program is out of memory (just a breakpoint inside the function and follow the variables)

But seems like you have a problem in WDict->sw.valid_words[i], maybe in some moment you are searching inside sw and position i doesn't exist.

Also, if you are working with Visual Studio, check if "this" pointer is always active or the debugger "deletes" it. If you have the default configuration of visual studio, sometimes, the this pointer could be deleted, reborn again, be deleted again... it's kinda strange but it happened to me twice.

ignoramous
15th May 2009, 17:30
I'm working with Qt Creator(the ui-> pointer thing makes it obvious?). And never does the index 'i' exceed the arraybounds. I've checked that with gdb.

The error Qt throws seems to be random (at least to me) when I call that function (getWildCards(word)) and most of the times it throws no error at all. I cannot know why this happens. For most part it seemed like the error was in the function trie_wildcard_print, but again gdb showed it to work well without any traces of leaks or illegal access.

And back to the errors that Qt throws, most frequently a dialog box with "Microsoft Visual C++ Runtime Library Error," some other times "QMutex: lock: Deadlock detected in Thread <threadno>," or it just exits with a code 128 or code 3. I'm using no threads whatsoever.

Also I'd be glad if you can point me to a good tutorial on using this inbuilt Qt Creator debugger. I've searched but didn't find a website that would explain it in simple English.

Thanks once again for your reply :).

jano_alex_es
18th May 2009, 08:08
I'm working with Qt Creator(the ui-> pointer thing makes it obvious?)

Not really... if you work with the Visual Studio Integrator it creates and sets up the ui object as well :P One of your error messages was "Microsoft Visual C++ Runtime Error" so I though you were working with Visual Studio.

I don't have a clue... if I were you I'll try to uninstall and install again everything :S Maybe an installation problem...

wysota
18th May 2009, 09:34
Let me guess - you are using multiple threads in your application, right?