From 1734d5e584a52b1bd2cf2baff2b09377bc36c39a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Jun 2015 15:05:55 -0700 Subject: [PATCH 1/3] Fix recalculateMeshBoxes being called outside of mutex --- libraries/render-utils/src/Model.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 1b991f2179..795e184735 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -545,11 +545,6 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g // we can use the AABox's ray intersection by mapping our origin and direction into the model frame // and testing intersection there. if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, distance, face)) { - - if (!_calculatedMeshBoxesValid) { - recalculateMeshBoxes(pickAgainstTriangles); - } - float bestDistance = std::numeric_limits::max(); float distanceToSubMesh; @@ -560,6 +555,11 @@ bool Model::findRayIntersectionAgainstSubMeshes(const glm::vec3& origin, const g // If we hit the models box, then consider the submeshes... _mutex.lock(); + + if (!_calculatedMeshBoxesValid) { + recalculateMeshBoxes(pickAgainstTriangles); + } + foreach(const AABox& subMeshBox, _calculatedMeshBoxes) { if (subMeshBox.findRayIntersection(origin, direction, distanceToSubMesh, subMeshFace)) { From a7f291154b0a39ad59be65013aadf900605609be Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Jun 2015 16:28:58 -0700 Subject: [PATCH 2/3] Add lock around recalculateMeshPartOffsets call --- libraries/render-utils/src/Model.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 795e184735..086139c646 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -1811,7 +1811,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran // We need to make sure we have valid offsets calculated before we can render if (!_calculatedMeshPartOffsetValid) { + _mutex.lock(); recalculateMeshPartOffsets(); + _mutex.unlock(); } auto textureCache = DependencyManager::get(); From 1371f775ee23cdb3b397b92def310eca4c1e5f11 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 19 Jun 2015 16:51:13 -0700 Subject: [PATCH 3/3] Add mutex lock around access to Model::_calculatedMeshPartOffset --- libraries/render-utils/src/Model.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 086139c646..1397512f4a 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -2021,7 +2021,9 @@ void Model::renderPart(RenderArgs* args, int meshIndex, int partIndex, bool tran } } + _mutex.lock(); qint64 offset = _calculatedMeshPartOffset[QPair(meshIndex, partIndex)]; + _mutex.unlock(); if (part.quadIndices.size() > 0) { batch.drawIndexed(gpu::QUADS, part.quadIndices.size(), offset);