diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-09 12:19:02 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2013-03-09 12:19:02 (GMT) |
| commit | 6090f0b0aaf302612f363cd3d85408e3b7d1150b (patch) | |
| tree | c249723f07b4fbfd2e8dfc9e0881dfd34069af54 /src | |
| parent | 189f96d35f220e7aad525fb790f231ae4edf5779 (diff) | |
| download | powder-6090f0b0aaf302612f363cd3d85408e3b7d1150b.zip powder-6090f0b0aaf302612f363cd3d85408e3b7d1150b.tar.gz | |
Don't leak saveComments vector in PreviewModel, also don't create unnecessary duplicate in PreviewView
Diffstat (limited to 'src')
| -rw-r--r-- | src/preview/PreviewModel.cpp | 3 | ||||
| -rw-r--r-- | src/preview/PreviewView.cpp | 21 | ||||
| -rw-r--r-- | src/preview/PreviewView.h | 1 |
3 files changed, 14 insertions, 11 deletions
diff --git a/src/preview/PreviewModel.cpp b/src/preview/PreviewModel.cpp index cb8adfd..8a0ff59 100644 --- a/src/preview/PreviewModel.cpp +++ b/src/preview/PreviewModel.cpp @@ -166,7 +166,7 @@ void PreviewModel::UpdateComments(int pageNumber) { for(int i = 0; i < saveComments->size(); i++) delete saveComments->at(i); - saveComments->clear(); + delete saveComments; saveComments = NULL; } @@ -295,6 +295,7 @@ void PreviewModel::Update() for(int i = 0; i < saveComments->size(); i++) delete saveComments->at(i); saveComments->clear(); + delete saveComments; saveComments = NULL; } commentsLoaded = true; diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 1859a2a..005cef9 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -489,15 +489,18 @@ void PreviewView::NotifyCommentsPageChanged(PreviewModel * sender) void PreviewView::NotifyCommentsChanged(PreviewModel * sender) { - if(sender->GetComments()) - { - comments = std::vector<SaveComment>(sender->GetComments()->begin(), sender->GetComments()->end()); - } - else + std::vector<SaveComment*> * comments = sender->GetComments(); + + for(int i = 0; i < commentComponents.size(); i++) { - comments.clear(); + commentsPanel->RemoveChild(commentComponents[i]); + delete commentComponents[i]; } + commentComponents.clear(); + commentTextComponents.clear(); + commentsPanel->InnerSize = ui::Point(0, 0); + if(comments) { for(int i = 0; i < commentComponents.size(); i++) { @@ -510,10 +513,10 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender) int currentY = 0;//-yOffset; ui::Label * tempUsername; ui::Label * tempComment; - for(int i = 0; i < comments.size(); i++) + for(int i = 0; i < comments->size(); i++) { int usernameY = currentY+5, commentY; - tempUsername = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 13), 16), comments[i].authorName); + tempUsername = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 13), 16), comments->at(i)->authorName); tempUsername->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom; currentY += 16; @@ -523,7 +526,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender) commentY = currentY+5; - tempComment = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 13), -1), comments[i].comment); + tempComment = new ui::Label(ui::Point(5, currentY+5), ui::Point(Size.X-((XRES/2) + 13), -1), comments->at(i)->comment); tempComment->SetMultiline(true); tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop; diff --git a/src/preview/PreviewView.h b/src/preview/PreviewView.h index 10dba4d..03a3a47 100644 --- a/src/preview/PreviewView.h +++ b/src/preview/PreviewView.h @@ -37,7 +37,6 @@ class PreviewView: public ui::Window { ui::Label * viewsLabel; ui::Textbox * saveIDTextbox; ui::ScrollPanel * commentsPanel; - std::vector<SaveComment> comments; std::vector<ui::Component*> commentComponents; std::vector<ui::Component*> commentTextComponents; int votesUp; |
