Skip to content

Commit 73a92b5

Browse files
committed
Fix crashes
1 parent 915af18 commit 73a92b5

3 files changed

Lines changed: 36 additions & 15 deletions

File tree

source/FolderDisplay.hpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,28 @@
1717
typedef function<void(float progress, DirectoryData* data)> progCallback;
1818

1919
class FolderDisplay : public FolderDisplayBase{
20+
DirectoryData* data = nullptr;
2021
public:
21-
DirectoryData* data;
22+
void Dealloc(){
23+
delete data;
24+
data = nullptr;
25+
}
26+
27+
void Recalculate(){
28+
data->recalculateStats();
29+
}
30+
31+
decltype(DirectoryData::size) GetSize() const{
32+
return data->size;
33+
}
34+
35+
const decltype(DirectoryData::Path)& GetPath() const{
36+
return data->Path;
37+
}
38+
39+
void SetData(decltype(data) newptr){
40+
data = newptr;
41+
}
2242

2343
FolderDisplay(wxWindow*,wxWindow*, DirectoryData*);
2444
~FolderDisplay();

source/interface_derived.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ MainFrame::MainFrame(wxWindow* parent) : MainFrameBase( parent )
101101
*/
102102
void MainFrame::SizeRootFolder(const string& folder){
103103
//deallocate existing data
104-
delete currentDisplay[0]->data;
104+
currentDisplay[0]->Dealloc();
105105
//clear the log
106106
logCtrl->SetValue("");
107107
//hide the log
@@ -123,14 +123,14 @@ void MainFrame::SizeRootFolder(const string& folder){
123123
wxPostEvent(this, event);
124124
};
125125
currentDisplay[0]->Clear();
126-
currentDisplay[0]->data = new DirectoryData(folder, true);
126+
currentDisplay[0]->SetData(new DirectoryData(folder, true));
127127
wxDataViewItem i;
128128

129129
//reset viewing area
130-
// for (int i = 1; i < currentDisplay.size(); i++){
131-
// delete currentDisplay[i]->data;
132-
// currentDisplay[i]->Destroy();
133-
// }
130+
for (int i = 1; i < currentDisplay.size(); i++){
131+
currentDisplay[i]->Dealloc();
132+
currentDisplay[i]->Destroy();
133+
}
134134
currentDisplay.erase(currentDisplay.begin()+1,currentDisplay.end());
135135
//update sizer size
136136
scrollSizer->SetCols(1);
@@ -244,10 +244,10 @@ void MainFrame::OnReloadFolder(wxCommandEvent& event){
244244
int index = 0;
245245
int parent_idx = 0;
246246
for(FolderDisplay* disp : currentDisplay){
247-
if (selected->parent != nullptr && disp->data->Path == selected->parent->Path){
247+
if (selected->parent != nullptr && disp->GetPath() == selected->Path){
248248
parent_idx = index;
249249
}
250-
if (disp->data->Path == selected->Path){
250+
if (disp->GetPath() == selected->Path){
251251
toReload = disp;
252252
break;
253253
}
@@ -257,7 +257,7 @@ void MainFrame::OnReloadFolder(wxCommandEvent& event){
257257
//not opened? open it first
258258
if (toReload == nullptr){
259259
toReload = ChangeSelection(selected);
260-
toReload->data = selected;
260+
toReload->SetData(selected);
261261
}
262262

263263
FolderDisplay* fdisp = currentDisplay[parent_idx];
@@ -302,7 +302,7 @@ void MainFrame::OnOpenFolder(wxCommandEvent& event){
302302
void MainFrame::OnExit(wxCommandEvent& event)
303303
{
304304
//deallocate structure
305-
delete currentDisplay[0]->data;
305+
currentDisplay[0]->Dealloc();
306306
Close( true );
307307
}
308308
/**
@@ -370,7 +370,7 @@ FolderDisplay* MainFrame::ChangeSelection(DirectoryData* sender){
370370
//find where the sender is in the list
371371
int idx;
372372
for (idx = 0; idx < currentDisplay.size(); idx++){
373-
if (currentDisplay[idx]->data->Path == sender->parent->Path){
373+
if (currentDisplay[idx]->GetPath() == sender->parent->Path){
374374
break;
375375
}
376376
}

source/interface_derived.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ class MainFrame : public MainFrameBase
4444
void ProgressUpdate(int progress){
4545
progressBar->SetValue(progress);
4646
if (progress == 100){
47-
currentDisplay[0]->data->recalculateStats();
47+
currentDisplay[0]->Recalculate();
4848
for (FolderDisplay* disp : currentDisplay){
4949
disp->UpdateTitle();
5050
}
5151
}
52-
UpdateTitlebar(progress, FolderDisplay::sizeToString(currentDisplay[0]->data->size));
52+
fileSize size = currentDisplay[0]->GetSize();
53+
UpdateTitlebar(progress, FolderDisplay::sizeToString(size));
5354
}
5455

5556
FolderDisplay* AddDisplay(DirectoryData* model){
@@ -124,7 +125,7 @@ class MainFrame : public MainFrameBase
124125
}
125126
}
126127
void UpdateTitlebar(int prog, const string& size) {
127-
SetTitle(AppName + " v" + AppVersion + " - Sizing " + to_string(prog) + "% " + currentDisplay[0]->data->Path + " [" + size + "]");
128+
SetTitle(AppName + " v" + AppVersion + " - Sizing " + to_string(prog) + "% " + currentDisplay[0]->GetPath() + " [" + size + "]");
128129
}
129130
wxDECLARE_EVENT_TABLE();
130131

0 commit comments

Comments
 (0)