Try to do non-main thread crash save/screenshot in main thread
This commit is contained in:
@@ -78,6 +78,7 @@
|
|||||||
/* static */ const char *CrashLog::message = NULL;
|
/* static */ const char *CrashLog::message = NULL;
|
||||||
/* static */ char *CrashLog::gamelog_buffer = NULL;
|
/* static */ char *CrashLog::gamelog_buffer = NULL;
|
||||||
/* static */ const char *CrashLog::gamelog_last = NULL;
|
/* static */ const char *CrashLog::gamelog_last = NULL;
|
||||||
|
/* static */ const CrashLog *CrashLog::main_thread_pending_crashlog = NULL;
|
||||||
|
|
||||||
char *CrashLog::LogCompiler(char *buffer, const char *last) const
|
char *CrashLog::LogCompiler(char *buffer, const char *last) const
|
||||||
{
|
{
|
||||||
@@ -534,8 +535,33 @@ bool CrashLog::MakeCrashLog() const
|
|||||||
printf("Crash dump written to %s. Please add this file to any bug reports.\n\n", filename);
|
printf("Crash dump written to %s. Please add this file to any bug reports.\n\n", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsNonMainThread()) {
|
||||||
|
printf("Asking main thread to write crash savegame and screenshot...\n\n");
|
||||||
|
CrashLog::main_thread_pending_crashlog = this;
|
||||||
|
_exit_game = true;
|
||||||
|
CSleep(60000);
|
||||||
|
if (!CrashLog::main_thread_pending_crashlog) return ret;
|
||||||
|
printf("Main thread did not write crash savegame and screenshot within 60s, trying it from this thread...\n\n");
|
||||||
|
}
|
||||||
|
CrashLog::main_thread_pending_crashlog = nullptr;
|
||||||
|
bret = CrashLog::MakeCrashSavegameAndScreenshot();
|
||||||
|
if (!bret) ret = false;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a crash dump and crash savegame. It uses DEBUG to write
|
||||||
|
* information like paths to the console.
|
||||||
|
* @return true when everything is made successfully.
|
||||||
|
*/
|
||||||
|
bool CrashLog::MakeCrashSavegameAndScreenshot() const
|
||||||
|
{
|
||||||
|
char filename[MAX_PATH];
|
||||||
|
bool ret = true;
|
||||||
|
|
||||||
printf("Writing crash savegame...\n");
|
printf("Writing crash savegame...\n");
|
||||||
bret = this->WriteSavegame(filename, lastof(filename));
|
bool bret = this->WriteSavegame(filename, lastof(filename));
|
||||||
if (bret) {
|
if (bret) {
|
||||||
printf("Crash savegame written to %s. Please add this file and the last (auto)save to any bug reports.\n\n", filename);
|
printf("Crash savegame written to %s. Please add this file and the last (auto)save to any bug reports.\n\n", filename);
|
||||||
} else {
|
} else {
|
||||||
@@ -555,6 +581,18 @@ bool CrashLog::MakeCrashLog() const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */ void CrashLog::MainThreadExitCheckPendingCrashlog()
|
||||||
|
{
|
||||||
|
const CrashLog *cl = CrashLog::main_thread_pending_crashlog;
|
||||||
|
if (cl) {
|
||||||
|
CrashLog::main_thread_pending_crashlog = nullptr;
|
||||||
|
cl->MakeCrashSavegameAndScreenshot();
|
||||||
|
|
||||||
|
CrashLog::AfterCrashLogCleanup();
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a message for the error message handler.
|
* Sets a message for the error message handler.
|
||||||
* @param message The error message of the error.
|
* @param message The error message of the error.
|
||||||
|
@@ -127,6 +127,7 @@ public:
|
|||||||
bool WriteScreenshot(char *filename, const char *filename_last) const;
|
bool WriteScreenshot(char *filename, const char *filename_last) const;
|
||||||
|
|
||||||
bool MakeCrashLog() const;
|
bool MakeCrashLog() const;
|
||||||
|
bool MakeCrashSavegameAndScreenshot() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialiser for crash logs; do the appropriate things so crashes are
|
* Initialiser for crash logs; do the appropriate things so crashes are
|
||||||
@@ -141,6 +142,10 @@ public:
|
|||||||
inline const char *GetMessage() const { return this->message; }
|
inline const char *GetMessage() const { return this->message; }
|
||||||
|
|
||||||
static const char *GetAbortCrashlogReason();
|
static const char *GetAbortCrashlogReason();
|
||||||
|
|
||||||
|
static const CrashLog *main_thread_pending_crashlog;
|
||||||
|
|
||||||
|
static void MainThreadExitCheckPendingCrashlog();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CRASHLOG_H */
|
#endif /* CRASHLOG_H */
|
||||||
|
@@ -890,6 +890,8 @@ int openttd_main(int argc, char *argv[])
|
|||||||
|
|
||||||
VideoDriver::GetInstance()->MainLoop();
|
VideoDriver::GetInstance()->MainLoop();
|
||||||
|
|
||||||
|
CrashLog::MainThreadExitCheckPendingCrashlog();
|
||||||
|
|
||||||
WaitTillSaved();
|
WaitTillSaved();
|
||||||
|
|
||||||
/* only save config if we have to */
|
/* only save config if we have to */
|
||||||
|
Reference in New Issue
Block a user