PDA

View Full Version : It works once, but crashes if I do it again



Astrognome
23rd March 2012, 21:08
I call this code on the startup of the application, but if I call it again, it crashes without any errors.


void MCM::repopWList()
{
QDir mcDir = QDir(McFolder);
QDir backupsDir = QDir(McFolder);
mcDir.cd("saves");
backupsDir.cd("MCM/backups");
mcDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
backupsDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);

ui->worldList->clear();

//list the worlds
QFileInfoList mcDirList = mcDir.entryInfoList();
for (int i = 0; i < mcDirList.size(); i++) {
QFileInfo fileInfo = mcDirList.at(i);
ui->worldList->addItem(fileInfo.fileName());
}
QFileInfoList backupsDirList = backupsDir.entryInfoList();
for (int i = 0; i < backupsDirList.size(); i++)
{
bool wExist = false;
QFileInfo backupInfo = backupsDirList.at(i);
for (int j = 0; j < ui->worldList->count(); j++)
{
string itemText = ui->worldList->item(j)->text().toStdString();
if (itemText == backupInfo.fileName().toStdString())
{
wExist = true;
}
}
if (wExist == false)
{
QString newWorld(backupInfo.fileName());
ui->worldList->addItem(newWorld);
}
}
}

ChrisW67
23rd March 2012, 21:59
Have you run it in your debugger and looked at the backtrace you get when it crashes? What line causes the crash?

Astrognome
27th March 2012, 19:33
I get EXC_BAD_ACCESS

caused by


ui->worldList->clear()

ChrisW67
28th March 2012, 00:06
Is ui->worldList a valid pointer? Have you deleted (or called deleteLater()) on the list at any time? Does any other part of your program hold a pointer to any QListWidgetItem in the list?