Skip to content

Commit

Permalink
Fixed crash handler save path when plugin crashed
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Jan 23, 2024
1 parent 5ae60be commit 29618c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <Windows.h>
#endif //JUCE_WINDOWS

static std::string hostPath;

std::string getLocalTime() {
time_t nowTime;
time(&nowTime);
Expand Down Expand Up @@ -36,7 +38,7 @@ void applicationCrashHandler(void* info) {
std::replace(time.begin(), time.end(), ':', '_');

/** Get File Path */
std::filesystem::path projPath = std::filesystem::current_path();
std::filesystem::path projPath = std::filesystem::path{ ::hostPath };
std::filesystem::path projHLPath = projPath / (time + ".vshl.dmp");
std::filesystem::path projMLPath = projPath / (time + ".vsml.dmp");
std::filesystem::path projLLPath = projPath / (time + ".vsll.dmp");
Expand Down Expand Up @@ -72,3 +74,7 @@ const juce::Array<juce::File> getAllDumpFiles() {
return appDir.findChildFiles(juce::File::findFiles, false,
"*.vsll.dmp;*.vsml.dmp;*.vshl.dmp", juce::File::FollowSymlinks::no);
}

void initCrashHandler(const juce::String& path) {
::hostPath = path.toStdString();
}
2 changes: 2 additions & 0 deletions src/crash.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
void applicationCrashHandler(void*);

const juce::Array<juce::File> getAllDumpFiles();

void initCrashHandler(const juce::String& path);
20 changes: 18 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ class MainApplication : public juce::JUCEApplication {
private:
std::unique_ptr<Splash> splash = nullptr;

void initCrashHandler() {
InitTaskList::getInstance()->add(
[splash = Splash::SafePointer<Splash>(this->splash.get())] {
if (splash) { splash->showMessage("Init Crash Handler..."); }
}
);
InitTaskList::getInstance()->add(
[] {
::initCrashHandler(utils::getAppRootDir().getFullPathName());
}
);
};

void loadConfig() {
InitTaskList::getInstance()->add(
[splash = Splash::SafePointer<Splash>(this->splash.get())] {
Expand Down Expand Up @@ -404,7 +417,7 @@ class MainApplication : public juce::JUCEApplication {
);
InitTaskList::getInstance()->add(
[] {
auto dumpList = getAllDumpFiles();
auto dumpList = ::getAllDumpFiles();
if (!dumpList.isEmpty()) {
juce::String mes = TRANS("Found the following crash dump files. These files take up {DMPSIZE} of storage space, should they be deleted to save disk space?") + "\n";
size_t dumpSize = 0;
Expand Down Expand Up @@ -476,7 +489,7 @@ class MainApplication : public juce::JUCEApplication {
void setCrashHandler() {
InitTaskList::getInstance()->add(
[] {
juce::SystemStats::setApplicationCrashHandler(applicationCrashHandler);
juce::SystemStats::setApplicationCrashHandler(::applicationCrashHandler);
}
);
};
Expand All @@ -493,6 +506,9 @@ class MainApplication : public juce::JUCEApplication {
this->splash = std::make_unique<Splash>();
this->splash->setVisible(true);

/** Init Crash Handler */
this->initCrashHandler();

/** Load Config */
this->loadConfig();

Expand Down

0 comments on commit 29618c6

Please sign in to comment.