Skip to content

Commit db6e086

Browse files
Handle missing Backtrace/Crashpad DLLs gracefully (#236)
* Handle missing Backtrace/Crashpad DLLs gracefully * Format file and return on error --------- Co-authored-by: kdysput <[email protected]>
1 parent 1d340fc commit db6e086

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

Runtime/Native/Windows/NativeClient.cs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ private void HandleNativeCrashes(IDictionary<string, string> clientAttributes, I
108108
return;
109109
}
110110

111+
var backtraceCrashpadHandlerPath = GetDefaultPathToBacktraceCrashpadHandler(pluginDirectoryPath);
112+
if (string.IsNullOrEmpty(backtraceCrashpadHandlerPath) || !File.Exists(backtraceCrashpadHandlerPath))
113+
{
114+
Debug.LogWarning("Backtrace native integration status: Cannot find path to Backtrace Crashpad handler.");
115+
return;
116+
}
117+
111118
var databasePath = _configuration.CrashpadDatabasePath;
112119
if (string.IsNullOrEmpty(databasePath) || !Directory.Exists(_configuration.GetFullDatabasePath()))
113120
{
@@ -122,12 +129,20 @@ private void HandleNativeCrashes(IDictionary<string, string> clientAttributes, I
122129
Directory.CreateDirectory(databasePath);
123130
}
124131

125-
CaptureNativeCrashes = Initialize(
126-
minidumpUrl,
127-
databasePath,
128-
crashpadHandlerPath,
129-
attachments.ToArray(),
130-
attachments.Count());
132+
try
133+
{
134+
CaptureNativeCrashes = Initialize(
135+
minidumpUrl,
136+
databasePath,
137+
crashpadHandlerPath,
138+
attachments.ToArray(),
139+
attachments.Count());
140+
}
141+
catch (DllNotFoundException)
142+
{
143+
Debug.LogWarning("Backtrace native integration status: Can't load Backtrace DLL");
144+
return;
145+
}
131146

132147
if (!CaptureNativeCrashes)
133148
{
@@ -255,7 +270,7 @@ public IEnumerator SendMinidumpOnStartup(ICollection<string> clientAttachments,
255270
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), tempDirectory),
256271
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), tempDirectory)
257272
};
258-
273+
259274
List<string> nativeCrashesDirs = new List<string>();
260275
foreach (string direcotry in crashDirectories)
261276
{
@@ -328,8 +343,16 @@ private string GetDefaultPathToCrashpadHandler(string pluginDirectoryPath)
328343
const string supportedArchitecture = "x86_64";
329344
var architectureDirectory = Path.Combine(pluginDirectoryPath, supportedArchitecture);
330345
return Path.Combine(architectureDirectory, crashpadHandlerName);
346+
}
331347

348+
private string GetDefaultPathToBacktraceCrashpadHandler(string pluginDirectoryPath)
349+
{
350+
const string crashpadHandlerName = "BacktraceCrashpadWindows.dll";
351+
const string supportedArchitecture = "x86_64";
352+
var architectureDirectory = Path.Combine(pluginDirectoryPath, supportedArchitecture);
353+
return Path.Combine(architectureDirectory, crashpadHandlerName);
332354
}
355+
333356
/// <summary>
334357
/// Clean scoped attributes
335358
/// </summary>

0 commit comments

Comments
 (0)