Skip to content

Commit

Permalink
Fix crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravbug committed Sep 27, 2021
1 parent 915af18 commit 73a92b5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
22 changes: 21 additions & 1 deletion source/FolderDisplay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@
typedef function<void(float progress, DirectoryData* data)> progCallback;

class FolderDisplay : public FolderDisplayBase{
DirectoryData* data = nullptr;
public:
DirectoryData* data;
void Dealloc(){
delete data;
data = nullptr;
}

void Recalculate(){
data->recalculateStats();
}

decltype(DirectoryData::size) GetSize() const{
return data->size;
}

const decltype(DirectoryData::Path)& GetPath() const{
return data->Path;
}

void SetData(decltype(data) newptr){
data = newptr;
}

FolderDisplay(wxWindow*,wxWindow*, DirectoryData*);
~FolderDisplay();
Expand Down
22 changes: 11 additions & 11 deletions source/interface_derived.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ MainFrame::MainFrame(wxWindow* parent) : MainFrameBase( parent )
*/
void MainFrame::SizeRootFolder(const string& folder){
//deallocate existing data
delete currentDisplay[0]->data;
currentDisplay[0]->Dealloc();
//clear the log
logCtrl->SetValue("");
//hide the log
Expand All @@ -123,14 +123,14 @@ void MainFrame::SizeRootFolder(const string& folder){
wxPostEvent(this, event);
};
currentDisplay[0]->Clear();
currentDisplay[0]->data = new DirectoryData(folder, true);
currentDisplay[0]->SetData(new DirectoryData(folder, true));
wxDataViewItem i;

//reset viewing area
// for (int i = 1; i < currentDisplay.size(); i++){
// delete currentDisplay[i]->data;
// currentDisplay[i]->Destroy();
// }
for (int i = 1; i < currentDisplay.size(); i++){
currentDisplay[i]->Dealloc();
currentDisplay[i]->Destroy();
}
currentDisplay.erase(currentDisplay.begin()+1,currentDisplay.end());
//update sizer size
scrollSizer->SetCols(1);
Expand Down Expand Up @@ -244,10 +244,10 @@ void MainFrame::OnReloadFolder(wxCommandEvent& event){
int index = 0;
int parent_idx = 0;
for(FolderDisplay* disp : currentDisplay){
if (selected->parent != nullptr && disp->data->Path == selected->parent->Path){
if (selected->parent != nullptr && disp->GetPath() == selected->Path){
parent_idx = index;
}
if (disp->data->Path == selected->Path){
if (disp->GetPath() == selected->Path){
toReload = disp;
break;
}
Expand All @@ -257,7 +257,7 @@ void MainFrame::OnReloadFolder(wxCommandEvent& event){
//not opened? open it first
if (toReload == nullptr){
toReload = ChangeSelection(selected);
toReload->data = selected;
toReload->SetData(selected);
}

FolderDisplay* fdisp = currentDisplay[parent_idx];
Expand Down Expand Up @@ -302,7 +302,7 @@ void MainFrame::OnOpenFolder(wxCommandEvent& event){
void MainFrame::OnExit(wxCommandEvent& event)
{
//deallocate structure
delete currentDisplay[0]->data;
currentDisplay[0]->Dealloc();
Close( true );
}
/**
Expand Down Expand Up @@ -370,7 +370,7 @@ FolderDisplay* MainFrame::ChangeSelection(DirectoryData* sender){
//find where the sender is in the list
int idx;
for (idx = 0; idx < currentDisplay.size(); idx++){
if (currentDisplay[idx]->data->Path == sender->parent->Path){
if (currentDisplay[idx]->GetPath() == sender->parent->Path){
break;
}
}
Expand Down
7 changes: 4 additions & 3 deletions source/interface_derived.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class MainFrame : public MainFrameBase
void ProgressUpdate(int progress){
progressBar->SetValue(progress);
if (progress == 100){
currentDisplay[0]->data->recalculateStats();
currentDisplay[0]->Recalculate();
for (FolderDisplay* disp : currentDisplay){
disp->UpdateTitle();
}
}
UpdateTitlebar(progress, FolderDisplay::sizeToString(currentDisplay[0]->data->size));
fileSize size = currentDisplay[0]->GetSize();
UpdateTitlebar(progress, FolderDisplay::sizeToString(size));
}

FolderDisplay* AddDisplay(DirectoryData* model){
Expand Down Expand Up @@ -124,7 +125,7 @@ class MainFrame : public MainFrameBase
}
}
void UpdateTitlebar(int prog, const string& size) {
SetTitle(AppName + " v" + AppVersion + " - Sizing " + to_string(prog) + "% " + currentDisplay[0]->data->Path + " [" + size + "]");
SetTitle(AppName + " v" + AppVersion + " - Sizing " + to_string(prog) + "% " + currentDisplay[0]->GetPath() + " [" + size + "]");
}
wxDECLARE_EVENT_TABLE();

Expand Down

0 comments on commit 73a92b5

Please sign in to comment.