diff options
author | Robert Morell <rmorell@nvidia.com> | 2017-02-01 14:51:00 -0800 |
---|---|---|
committer | Tony-LunarG <tony@lunarg.com> | 2017-02-02 15:18:41 -0700 |
commit | c0ee2e5a90b47a08692aae4b308bc3884eff0d5f (patch) | |
tree | 952351f91cdf75c40e387d896656c8fb834e69a9 /demos | |
parent | fc76d6bcc9392050f9dfce315358ad7f2bd8761d (diff) |
cube: Error handling improvements
- Add a newline to the end of the error message when printing to stdout
for ERR_EXIT.
- Handle demo_read_spv failures by calling ERR_EXIT rather than just
continuing on and calling the Vulkan library with a NULL pointer.
Diffstat (limited to 'demos')
-rw-r--r-- | demos/cube.c | 8 | ||||
-rw-r--r-- | demos/cube.cpp | 8 |
2 files changed, 14 insertions, 2 deletions
diff --git a/demos/cube.c b/demos/cube.c index 0abffae6..4b84ae64 100644 --- a/demos/cube.c +++ b/demos/cube.c @@ -91,7 +91,7 @@ bool in_callback = false; #else #define ERR_EXIT(err_msg, err_class) \ do { \ - printf(err_msg); \ + printf("%s\n", err_msg); \ fflush(stdout); \ exit(1); \ } while (0) @@ -1661,6 +1661,9 @@ static VkShaderModule demo_prepare_vs(struct demo *demo) { size_t size; vertShaderCode = demo_read_spv("cube-vert.spv", &size); + if (!vertShaderCode) { + ERR_EXIT("Failed to load cube-vert.spv", "Load Shader Failure"); + } demo->vert_shader_module = demo_prepare_shader_module(demo, vertShaderCode, size); @@ -1686,6 +1689,9 @@ static VkShaderModule demo_prepare_fs(struct demo *demo) { size_t size; fragShaderCode = demo_read_spv("cube-frag.spv", &size); + if (!fragShaderCode) { + ERR_EXIT("Failed to load cube-frag.spv", "Load Shader Failure"); + } demo->frag_shader_module = demo_prepare_shader_module(demo, fragShaderCode, size); diff --git a/demos/cube.cpp b/demos/cube.cpp index e5fa6ae2..096bf0b0 100644 --- a/demos/cube.cpp +++ b/demos/cube.cpp @@ -64,7 +64,7 @@ #else #define ERR_EXIT(err_msg, err_class) \ do { \ - printf(err_msg); \ + printf("%s\n", err_msg); \ fflush(stdout); \ exit(1); \ } while (0) @@ -1555,6 +1555,9 @@ struct Demo { vk::ShaderModule prepare_fs() { size_t size = 0; void *fragShaderCode = read_spv("cube-frag.spv", &size); + if (!fragShaderCode) { + ERR_EXIT("Failed to load cube-frag.spv", "Load Shader Failure"); + } frag_shader_module = prepare_shader_module(fragShaderCode, size); @@ -1861,6 +1864,9 @@ struct Demo { vk::ShaderModule prepare_vs() { size_t size = 0; void *vertShaderCode = read_spv("cube-vert.spv", &size); + if (!vertShaderCode) { + ERR_EXIT("Failed to load cube-vert.spv", "Load Shader Failure"); + } vert_shader_module = prepare_shader_module(vertShaderCode, size); |