From 115454929f637c0942b7bc0d1250c9ab8666ecf1 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 18 Sep 2005 18:55:48 +0000 Subject: [PATCH] Segfault fix on deleting dir --- vrecordinglist.cc | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/vrecordinglist.cc b/vrecordinglist.cc index f0f7a38..9ecbf89 100644 --- a/vrecordinglist.cc +++ b/vrecordinglist.cc @@ -42,6 +42,8 @@ VRecordingList::VRecordingList(VRecordingList* tparent) sl.setSurface(surface); sl.setSurfaceOffset(10, 30 + 5); sl.setDimensions(width - 20, height - 30 - 15 - 30); + + Log::getInstance()->log("VRecordingList", Log::DEBUG, "this=%p parent=%p\n", this, myParent); } VRecordingList::~VRecordingList() @@ -81,17 +83,27 @@ void VRecordingList::drawData() struct tm* btime; Directory* dir; - for (DirectoryList::iterator i = recDir->dirList.begin(); i != recDir->dirList.end(); i++) + DirectoryList::iterator i; + + // First go through to delete 1 empty dir if necessary + + for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++) { dir = *i; if (dir->getNumRecordings() == 0) { recDir->dirList.erase(i); - continue; + delete dir; + break; } + } - snprintf(tempA, 299, " %lu\t%s", dir->getNumRecordings(), dir->name); + // Then go through again to draw data. Don't merge these two loops! + for (i = recDir->dirList.begin(); i != recDir->dirList.end(); i++) + { + dir = *i; + snprintf(tempA, 299, " %lu\t%s", dir->getNumRecordings(), dir->name); dir->index = sl.addOption(tempA, first); first = 0; } @@ -202,6 +214,7 @@ void VRecordingList::processMessage(Message* m) if (m->message == Message::REDRAW_DATA) { dataInvalid = 1; + draw(); return; } } @@ -217,14 +230,14 @@ void VRecordingList::doDeleteSelected() { saveIndex = toDelete->index; saveTop = sl.getTopOption(); - Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s\n", toDelete->index, toDelete->getProgName(), toDelete->fileName); + Log::getInstance()->log("VRecordingList", Log::DEBUG, "FOUND: %i %s %s", toDelete->index, toDelete->getProgName(), toDelete->fileName); for(RecordingList::iterator i = recDir->recList.begin(); i != recDir->recList.end(); i++) { if (*i == toDelete) { recDir->recList.erase(i); - Log::getInstance()->log("VRecordingList", Log::DEBUG, "Removed from vector: %s %s\n", toDelete->getProgName(), toDelete->fileName); + Log::getInstance()->log("VRecordingList", Log::DEBUG, "Removed from vector: %s %s", toDelete->getProgName(), toDelete->fileName); break; } } -- 2.39.5