Skip to content

Commit 65a87b9

Browse files
committed
Fix for _meshStates.empty() assertion
See the comment in the code for a detailed discussion of the issue. This is a workaround, but it should be a safe one.
1 parent bfbbb2f commit 65a87b9

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

libraries/render-utils/src/Model.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,20 @@ bool Model::updateGeometry() {
295295
// TODO: should all Models have a valid _rig?
296296
if (_rig.jointStatesEmpty() && getHFMModel().joints.size() > 0) {
297297
initJointStates();
298-
assert(_meshStates.empty());
298+
299+
if (!_meshStates.empty()) {
300+
// See https://github.com/vircadia/vircadia/issues/958 for a discussion of the issues found here with
301+
// a previously existing assert, and the likely reasons for things going wrong here.
302+
//
303+
// TL;DR: There may be a threading issue, or it could be due to something lacking joints, which would cause
304+
// initJointStates() to fail to make _rig.jointStatesEmpty() false, causing things to end up here twice.
305+
//
306+
// In any case it appears to be safe to simply clear _meshStates here, even though this shouldn't happen.
307+
_meshStates.clear();
308+
qCWarning(renderutils) << "_meshStates has" << _meshStates.size() << "items when it should have none. Model with URL "
309+
<< _url.toString() << "; translation" << _translation << "; rotation" << _rotation << "; scale" << _scale
310+
<< "; joint state count" << _rig.getJointStateCount() << "; type" << (modelProviderType == NestableType::Avatar ? "Avatar" : "Entity");
311+
}
299312

300313
const HFMModel& hfmModel = getHFMModel();
301314
int i = 0;
@@ -841,8 +854,8 @@ void Model::calculateTriangleSets(const HFMModel& hfmModel) {
841854
int i2 = part.quadIndices[vIndex++];
842855
int i3 = part.quadIndices[vIndex++];
843856

844-
// track the model space version... these points will be transformed by the FST's offset,
845-
// which includes the scaling, rotation, and translation specified by the FST/FBX,
857+
// track the model space version... these points will be transformed by the FST's offset,
858+
// which includes the scaling, rotation, and translation specified by the FST/FBX,
846859
// this can't change at runtime, so we can safely store these in our TriangleSet
847860
glm::vec3 v0 = glm::vec3(meshTransform * glm::vec4(mesh.vertices[i0], 1.0f));
848861
glm::vec3 v1 = glm::vec3(meshTransform * glm::vec4(mesh.vertices[i1], 1.0f));
@@ -863,8 +876,8 @@ void Model::calculateTriangleSets(const HFMModel& hfmModel) {
863876
int i1 = part.triangleIndices[vIndex++];
864877
int i2 = part.triangleIndices[vIndex++];
865878

866-
// track the model space version... these points will be transformed by the FST's offset,
867-
// which includes the scaling, rotation, and translation specified by the FST/FBX,
879+
// track the model space version... these points will be transformed by the FST's offset,
880+
// which includes the scaling, rotation, and translation specified by the FST/FBX,
868881
// this can't change at runtime, so we can safely store these in our TriangleSet
869882
glm::vec3 v0 = glm::vec3(meshTransform * glm::vec4(mesh.vertices[i0], 1.0f));
870883
glm::vec3 v1 = glm::vec3(meshTransform * glm::vec4(mesh.vertices[i1], 1.0f));

0 commit comments

Comments
 (0)