Allow printf-style formatting to be used in SK_ABORT.
SK_ABORT was already using SkDebugf to print the error message to the console, so all the moving parts were there. This CL just adds a mechanism for the calling code to pass in arguments. Added a use case to demonstrate usage--when an allocation fails, the requested size is now shown in the error message. Change-Id: I42f141151fb57a399c086926249816833f349ddb Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293272 Reviewed-by: Ben Wagner <bungeman@google.com> Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Ben Wagner <bungeman@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Commit-Queue: Herb Derby <herb@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
d9f2c5f58f
commit
67e50a6b5c
@ -61,9 +61,8 @@ public:
|
||||
void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
|
||||
int* startVertex) override {
|
||||
if (vertexSize * vertexCount > sizeof(fStaticVertexData)) {
|
||||
SK_ABORT(SkStringPrintf(
|
||||
"FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
|
||||
vertexSize * vertexCount, SK_ARRAY_COUNT(fStaticVertexData)).c_str());
|
||||
SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
|
||||
vertexSize * vertexCount, SK_ARRAY_COUNT(fStaticVertexData));
|
||||
}
|
||||
*startVertex = 0;
|
||||
return fStaticVertexData;
|
||||
@ -73,9 +72,8 @@ public:
|
||||
int drawCount, sk_sp<const GrBuffer>* buffer, size_t* offsetInBytes) override {
|
||||
int staticBufferCount = (int)SK_ARRAY_COUNT(fStaticDrawIndexedIndirectData);
|
||||
if (drawCount > staticBufferCount) {
|
||||
SK_ABORT(SkStringPrintf(
|
||||
"FATAL: wanted %i static drawIndexedIndirect elements; only have %i.\n",
|
||||
drawCount, staticBufferCount).c_str());
|
||||
SK_ABORT("FATAL: wanted %i static drawIndexedIndirect elements; only have %i.\n",
|
||||
drawCount, staticBufferCount);
|
||||
}
|
||||
return fStaticDrawIndexedIndirectData;
|
||||
}
|
||||
|
@ -285,22 +285,20 @@
|
||||
# define SK_DUMP_GOOGLE3_STACK()
|
||||
#endif
|
||||
|
||||
#ifdef SK_BUILD_FOR_WIN
|
||||
// Lets visual studio follow error back to source
|
||||
#define SK_DUMP_LINE_FORMAT(message) \
|
||||
SkDebugf("%s(%d): fatal error: \"%s\"\n", __FILE__, __LINE__, message)
|
||||
#else
|
||||
#define SK_DUMP_LINE_FORMAT(message) \
|
||||
SkDebugf("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, message)
|
||||
#endif
|
||||
|
||||
#ifndef SK_ABORT
|
||||
# define SK_ABORT(message) \
|
||||
# ifdef SK_BUILD_FOR_WIN
|
||||
// This style lets Visual Studio follow errors back to the source file.
|
||||
# define SK_DUMP_LINE_FORMAT "%s(%d)"
|
||||
# else
|
||||
# define SK_DUMP_LINE_FORMAT "%s:%d"
|
||||
# endif
|
||||
# define SK_ABORT(message, ...) \
|
||||
do { \
|
||||
SK_DUMP_LINE_FORMAT(message); \
|
||||
SK_DUMP_GOOGLE3_STACK(); \
|
||||
sk_abort_no_print(); \
|
||||
SkUNREACHABLE; \
|
||||
SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \
|
||||
__FILE__, __LINE__, ##__VA_ARGS__); \
|
||||
SK_DUMP_GOOGLE3_STACK(); \
|
||||
sk_abort_no_print(); \
|
||||
SkUNREACHABLE; \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
@ -465,7 +463,7 @@ SK_API extern void sk_abort_no_print(void);
|
||||
SK_ABORT("assert(" #cond ")"); \
|
||||
}() )
|
||||
#define SkDEBUGFAIL(message) SK_ABORT(message)
|
||||
#define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__)
|
||||
#define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__)
|
||||
#define SkDEBUGCODE(...) __VA_ARGS__
|
||||
#define SkDEBUGF(...) SkDebugf(__VA_ARGS__)
|
||||
#define SkAssertResult(cond) SkASSERT(cond)
|
||||
|
@ -37,9 +37,7 @@ static jmethodID gInputStream_skipMethodID;
|
||||
static JNIEnv* get_env_or_die(JavaVM* jvm) {
|
||||
JNIEnv* env;
|
||||
if (jvm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
|
||||
char errorMessage[256];
|
||||
sprintf(errorMessage, "Failed to get JNIEnv for JavaVM: %p", jvm);
|
||||
SK_ABORT(errorMessage);
|
||||
SK_ABORT("Failed to get JNIEnv for JavaVM: %p", jvm);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ GrBlockAllocator::ByteRange GrBlockAllocator::allocate(size_t size) {
|
||||
<= std::numeric_limits<int32_t>::max());
|
||||
|
||||
if (size > kMaxAllocationSize) {
|
||||
SK_ABORT("Allocation too large");
|
||||
SK_ABORT("Allocation too large (%zu bytes requested)", size);
|
||||
}
|
||||
|
||||
int iSize = (int) size;
|
||||
|
@ -60,7 +60,7 @@ static GpuPathRenderers get_named_pathrenderers_flags(const char* name) {
|
||||
} else if (!strcmp(name, "default")) {
|
||||
return GpuPathRenderers::kDefault;
|
||||
}
|
||||
SK_ABORT(SkStringPrintf("error: unknown named path renderer \"%s\"\n", name).c_str());
|
||||
SK_ABORT("error: unknown named path renderer \"%s\"\n", name);
|
||||
}
|
||||
|
||||
static GpuPathRenderers collect_gpu_path_renderers_from_flags() {
|
||||
|
@ -573,7 +573,7 @@ int main(int argc, char** argv) {
|
||||
case Result::Ok: break;
|
||||
case Result::Skip: return false;
|
||||
case Result::Fail:
|
||||
SK_ABORT(result.failure.c_str());
|
||||
SK_ABORT("%s", result.failure.c_str());
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user