minor changes / fixes to last commit

This commit is contained in:
jacob1 2013-07-10 15:08:00 -04:00
parent 4f6904b1ed
commit e7a3fd1c29

View File

@ -23,7 +23,7 @@ void * PreviewModel::updateSaveInfoT(void * obj)
{ {
SaveInfo * tempSave = Client::Ref().GetSave(((threadInfo*)obj)->saveID, ((threadInfo*)obj)->saveDate); SaveInfo * tempSave = Client::Ref().GetSave(((threadInfo*)obj)->saveID, ((threadInfo*)obj)->saveDate);
((threadInfo*)obj)->threadFinished = true; ((threadInfo*)obj)->threadFinished = true;
if (((threadInfo*)obj)->previewExited) if (((threadInfo*)obj)->previewExited && tempSave)
delete tempSave; delete tempSave;
return tempSave; return tempSave;
} }
@ -36,8 +36,10 @@ void * PreviewModel::updateSaveDataT(void * obj)
((threadInfo*)obj)->threadFinished = true; ((threadInfo*)obj)->threadFinished = true;
if (((threadInfo*)obj)->previewExited) if (((threadInfo*)obj)->previewExited)
{ {
delete tempSave; if (tempSave)
free(tempData); delete tempSave;
if (tempData)
free(tempData);
} }
return tempSave; return tempSave;
} }
@ -46,7 +48,7 @@ void * PreviewModel::updateSaveCommentsT(void * obj)
{ {
std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(((threadInfo*)obj)->saveID, (((threadInfo*)obj)->saveDate-1)*20, 20); //saveDate is used as commentsPageNumber std::vector<SaveComment*> * tempComments = Client::Ref().GetComments(((threadInfo*)obj)->saveID, (((threadInfo*)obj)->saveDate-1)*20, 20); //saveDate is used as commentsPageNumber
((threadInfo*)obj)->threadFinished = true; ((threadInfo*)obj)->threadFinished = true;
if (((threadInfo*)obj)->previewExited) if (((threadInfo*)obj)->previewExited && tempComments)
{ {
for(int i = 0; i < tempComments->size(); i++) for(int i = 0; i < tempComments->size(); i++)
delete tempComments->at(i); delete tempComments->at(i);
@ -244,81 +246,74 @@ void PreviewModel::AddObserver(PreviewView * observer)
void PreviewModel::Update() void PreviewModel::Update()
{ {
if (updateSaveDataInfo) if (updateSaveDataInfo && updateSaveDataInfo->threadFinished)
{ {
if (updateSaveDataInfo->threadFinished) pthread_join(updateSaveDataThread, (void**)(&saveData));
{ delete updateSaveDataInfo;
delete updateSaveDataInfo; updateSaveDataInfo = NULL;
updateSaveDataInfo = NULL;
pthread_join(updateSaveDataThread, (void**)(&saveData));
if (save) if (save)
{
commentsTotal = save->Comments;
try
{
save->SetGameSave(new GameSave((char*)saveData->data, saveData->length));
}
catch(ParseException &e)
{
throw PreviewModelException("Save file corrupt or from newer version");
}
notifySaveChanged();
notifyCommentsPageChanged();
}
}
}
if (updateSaveInfoInfo)
{
if (updateSaveInfoInfo->threadFinished)
{ {
if (save) commentsTotal = save->Comments;
try
{ {
delete save; save->SetGameSave(new GameSave((char*)saveData->data, saveData->length));
save = NULL;
} }
delete updateSaveInfoInfo; catch(ParseException &e)
updateSaveInfoInfo = NULL;
pthread_join(updateSaveInfoThread, (void**)(&save));
if (save)
{ {
commentsTotal = save->Comments; throw PreviewModelException("Save file corrupt or from newer version");
try
{
save->SetGameSave(new GameSave((char*)saveData->data, saveData->length));
}
catch(ParseException &e)
{
throw PreviewModelException("Save file corrupt or from newer version");
}
notifyCommentsPageChanged();
} }
notifySaveChanged(); notifySaveChanged();
notifyCommentsPageChanged();
if(!save)
throw PreviewModelException("Unable to load save");
} }
} }
if (updateSaveCommentsInfo) if (updateSaveInfoInfo && updateSaveInfoInfo->threadFinished)
{ {
if (updateSaveCommentsInfo->threadFinished) if (save)
{ {
if(saveComments) delete save;
{ save = NULL;
for(int i = 0; i < saveComments->size(); i++)
delete saveComments->at(i);
saveComments->clear();
delete saveComments;
saveComments = NULL;
}
commentsLoaded = true;
delete updateSaveCommentsInfo;
updateSaveCommentsInfo = NULL;
pthread_join(updateSaveCommentsThread, (void**)(&saveComments));
notifySaveCommentsChanged();
} }
pthread_join(updateSaveInfoThread, (void**)(&save));
delete updateSaveInfoInfo;
updateSaveInfoInfo = NULL;
if (save)
{
commentsTotal = save->Comments;
try
{
save->SetGameSave(new GameSave((char*)saveData->data, saveData->length));
}
catch(ParseException &e)
{
throw PreviewModelException("Save file corrupt or from newer version");
}
notifyCommentsPageChanged();
}
notifySaveChanged();
if(!save)
throw PreviewModelException("Unable to load save");
}
if (updateSaveCommentsInfo && updateSaveCommentsInfo->threadFinished)
{
if(saveComments)
{
for(int i = 0; i < saveComments->size(); i++)
delete saveComments->at(i);
saveComments->clear();
delete saveComments;
saveComments = NULL;
}
commentsLoaded = true;
pthread_join(updateSaveCommentsThread, (void**)(&saveComments));
delete updateSaveCommentsInfo;
updateSaveCommentsInfo = NULL;
notifySaveCommentsChanged();
} }
} }