mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-12 11:24:04 +02:00
Don't leak saveComments vector in PreviewModel, also don't create unnecessary duplicate in PreviewView
This commit is contained in:
@@ -166,7 +166,7 @@ void PreviewModel::UpdateComments(int pageNumber)
|
|||||||
{
|
{
|
||||||
for(int i = 0; i < saveComments->size(); i++)
|
for(int i = 0; i < saveComments->size(); i++)
|
||||||
delete saveComments->at(i);
|
delete saveComments->at(i);
|
||||||
saveComments->clear();
|
delete saveComments;
|
||||||
saveComments = NULL;
|
saveComments = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,6 +295,7 @@ void PreviewModel::Update()
|
|||||||
for(int i = 0; i < saveComments->size(); i++)
|
for(int i = 0; i < saveComments->size(); i++)
|
||||||
delete saveComments->at(i);
|
delete saveComments->at(i);
|
||||||
saveComments->clear();
|
saveComments->clear();
|
||||||
|
delete saveComments;
|
||||||
saveComments = NULL;
|
saveComments = NULL;
|
||||||
}
|
}
|
||||||
commentsLoaded = true;
|
commentsLoaded = true;
|
||||||
|
@@ -489,15 +489,18 @@ void PreviewView::NotifyCommentsPageChanged(PreviewModel * sender)
|
|||||||
|
|
||||||
void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
||||||
{
|
{
|
||||||
if(sender->GetComments())
|
std::vector<SaveComment*> * comments = sender->GetComments();
|
||||||
{
|
|
||||||
comments = std::vector<SaveComment>(sender->GetComments()->begin(), sender->GetComments()->end());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
comments.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for(int i = 0; i < commentComponents.size(); i++)
|
||||||
|
{
|
||||||
|
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++)
|
for(int i = 0; i < commentComponents.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -510,10 +513,10 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
|||||||
int currentY = 0;//-yOffset;
|
int currentY = 0;//-yOffset;
|
||||||
ui::Label * tempUsername;
|
ui::Label * tempUsername;
|
||||||
ui::Label * tempComment;
|
ui::Label * tempComment;
|
||||||
for(int i = 0; i < comments.size(); i++)
|
for(int i = 0; i < comments->size(); i++)
|
||||||
{
|
{
|
||||||
int usernameY = currentY+5, commentY;
|
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.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
tempUsername->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||||
currentY += 16;
|
currentY += 16;
|
||||||
@@ -523,7 +526,7 @@ void PreviewView::NotifyCommentsChanged(PreviewModel * sender)
|
|||||||
|
|
||||||
|
|
||||||
commentY = currentY+5;
|
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->SetMultiline(true);
|
||||||
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
tempComment->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||||
tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
tempComment->Appearance.VerticalAlign = ui::Appearance::AlignTop;
|
||||||
|
@@ -37,7 +37,6 @@ class PreviewView: public ui::Window {
|
|||||||
ui::Label * viewsLabel;
|
ui::Label * viewsLabel;
|
||||||
ui::Textbox * saveIDTextbox;
|
ui::Textbox * saveIDTextbox;
|
||||||
ui::ScrollPanel * commentsPanel;
|
ui::ScrollPanel * commentsPanel;
|
||||||
std::vector<SaveComment> comments;
|
|
||||||
std::vector<ui::Component*> commentComponents;
|
std::vector<ui::Component*> commentComponents;
|
||||||
std::vector<ui::Component*> commentTextComponents;
|
std::vector<ui::Component*> commentTextComponents;
|
||||||
int votesUp;
|
int votesUp;
|
||||||
|
Reference in New Issue
Block a user