SkSLSlide: Guard against asserts in the compiler
Before compiling, write the shader text to 'sksl.bak', then remove it if we succeed. This avoids loss-of-work if you manage to uncover an assert. Change-Id: Idec7740210ce56cc9522c31e79f6aae1d4c3da1d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/343425 Commit-Queue: John Stiles <johnstiles@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
ad2d494272
commit
6c32c7ba81
@ -16,6 +16,7 @@
|
||||
#include "tools/viewer/Viewer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include "imgui.h"
|
||||
|
||||
using namespace sk_app;
|
||||
@ -88,7 +89,21 @@ bool SkSLSlide::rebuild() {
|
||||
"uniform float iTime;\n"
|
||||
"uniform float4 iMouse;\n");
|
||||
sksl.append(fSkSL);
|
||||
|
||||
// It shouldn't happen, but it's possible to assert in the compiler, especially mid-edit.
|
||||
// To guard against losing your work, write out the shader to a backup file, then remove it
|
||||
// when we compile successfully.
|
||||
constexpr char kBackupFile[] = "sksl.bak";
|
||||
FILE* backup = fopen(kBackupFile, "w");
|
||||
if (backup) {
|
||||
fwrite(fSkSL.c_str(), 1, fSkSL.size(), backup);
|
||||
fclose(backup);
|
||||
}
|
||||
auto [effect, errorText] = SkRuntimeEffect::Make(sksl);
|
||||
if (backup) {
|
||||
std::remove(kBackupFile);
|
||||
}
|
||||
|
||||
if (!effect) {
|
||||
Viewer::ShaderErrorHandler()->compileError(sksl.c_str(), errorText.c_str());
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user