From d180641246ee804ad2e2f82fc30993f36603225b Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sun, 23 Sep 2018 18:24:19 +0900 Subject: [PATCH] Do not draw skinned mesh(node) otherwise glview crashes. --- examples/glview/glview.cc | 14 ++++++++++++-- examples/glview/premake5.lua | 18 +++++++++++++++++- examples/glview/trackball.cc | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/glview/glview.cc b/examples/glview/glview.cc index 988a644..cf261ed 100644 --- a/examples/glview/glview.cc +++ b/examples/glview/glview.cc @@ -252,7 +252,7 @@ static void SetupMeshState(tinygltf::Model &model, GLuint progId) { const tinygltf::BufferView &bufferView = model.bufferViews[i]; if (bufferView.target == 0) { std::cout << "WARN: bufferView.target is zero" << std::endl; - continue; // Unsupported bufferView. + continue; // Unsupported or not directly used bufferView. } const tinygltf::Buffer &buffer = model.buffers[bufferView.buffer]; @@ -529,6 +529,13 @@ static void DrawMesh(tinygltf::Model &model, const tinygltf::Mesh &mesh) { for (; it != itEnd; it++) { assert(it->second >= 0); const tinygltf::Accessor &accessor = model.accessors[it->second]; + const tinygltf::BufferView &bufferView = model.bufferViews[accessor.bufferView]; + + if (bufferView.target == 0) { + // Unsupported or not directly used buffer + continue; + } + glBindBuffer(GL_ARRAY_BUFFER, gBufferState[accessor.bufferView].vb); CheckErrors("bind buffer"); int size = 1; @@ -668,7 +675,10 @@ static void DrawNode(tinygltf::Model &model, const tinygltf::Node &node) { // std::cout << it->first << std::endl; // FIXME(syoyo): Refactor. // DrawCurves(scene, it->second); - DrawMesh(model, model.meshes[node.mesh]); + + if ((node.mesh >= 0) && (node.mesh < int(model.meshes.size()))) { + DrawMesh(model, model.meshes[node.mesh]); + } // Draw child nodes. for (size_t i = 0; i < node.children.size(); i++) { diff --git a/examples/glview/premake5.lua b/examples/glview/premake5.lua index 98bffc8..bd93217 100644 --- a/examples/glview/premake5.lua +++ b/examples/glview/premake5.lua @@ -1,10 +1,20 @@ +newoption { + trigger = "asan", + description = "Enable Address Sanitizer(gcc5+ ang clang only)" +} + solution "glview" -- location ( "build" ) configurations { "Debug", "Release" } platforms {"native", "x64", "x32"} - + project "glview" + -- Use clang for better asan expericen + if _OPTIONS["asan"] then + toolset "clang" + end + kind "ConsoleApp" language "C++" cppdialect "C++11" @@ -13,6 +23,12 @@ solution "glview" includedirs { "../../" } configuration { "linux" } + + if _OPTIONS["asan"] then + buildoptions { "-fsanitize=address,undefined" } + linkoptions { "-fsanitize=address,undefined" } + end + linkoptions { "`pkg-config --libs glfw3`" } links { "GL", "GLU", "m", "GLEW", "X11", "Xrandr", "Xinerama", "Xi", "Xxf86vm", "Xcursor", "dl" } diff --git a/examples/glview/trackball.cc b/examples/glview/trackball.cc index 86ff3b3..27642e8 100644 --- a/examples/glview/trackball.cc +++ b/examples/glview/trackball.cc @@ -86,7 +86,7 @@ static void vsub(const float *src1, const float *src2, float *dst) { } static void vcopy(const float *v1, float *v2) { - register int i; + int i; for (i = 0; i < 3; i++) v2[i] = v1[i]; }