Skip to content

Commit

Permalink
Fix crash on missing weights data (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
lexaknyazev authored Jun 2, 2024
1 parent 146d44d commit 0cdee26
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 15 deletions.
24 changes: 10 additions & 14 deletions lib/src/data_access/validate_accessors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
library gltf.data_access.validate_accessors_data;

import 'package:gltf/src/base/gltf_property.dart';
import 'package:meta/meta.dart';

Accessor<T> _guardAccessor<T extends num>(Accessor<T> accessor) {
if (accessor == null) {
Expand Down Expand Up @@ -164,10 +163,7 @@ void validateAccessorsData(Gltf gltf, Context context) {

// add a checker from the current primitive to the global list
influencesCheckers.add(InfluencesChecker(context.getPointerString(),
jointsIterators: jointsIterators,
weightsIterators: weightsIterators,
maxJointIndex: maxJoints - 1,
limitingSkinIndex: limitingSkinIndex));
jointsIterators, weightsIterators, maxJoints - 1, limitingSkinIndex));

context.path
..removeLast()
Expand Down Expand Up @@ -225,9 +221,7 @@ void _processAccessorElements(Context context) {

for (final value in accessor.getElements()) {
for (var t = 0; t < elementCheckers.length; t++) {
if (!elementCheckers[t].check(context, index, componentIndex, value)) {
continue;
}
elementCheckers[t].check(context, index, componentIndex, value);
}

if (++componentIndex == components) {
Expand Down Expand Up @@ -262,11 +256,8 @@ class InfluencesChecker {
double _threshold = 0;
final Set<int> _currentIndices = <int>{};

InfluencesChecker(this.path,
{@required this.jointsIterators,
@required this.weightsIterators,
@required this.maxJointIndex,
@required this.limitingSkinIndex})
InfluencesChecker(this.path, this.jointsIterators, this.weightsIterators,
this.maxJointIndex, this.limitingSkinIndex)
: assert(jointsIterators.length == weightsIterators.length),
assert(maxJointIndex >= 0),
assert(limitingSkinIndex >= 0);
Expand Down Expand Up @@ -298,7 +289,12 @@ class InfluencesChecker {
}

final weight = weightsIterators[i].current;
assert(weight != null);

if (weight == null) {
// insufficient weights data
_done = true;
return;
}

if (weight != 0) {
var unique = true;
Expand Down
3 changes: 2 additions & 1 deletion test/base/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"index_buffer_primitive_restart.gltf": "Index buffer with primitive restart value",
"normals_tangents_non_unit_invalid_sign.gltf": "Non-unit normals and tangents, invalid sign",
"colors_non_clamped.gltf": "Non-clamped vertex colors",
"joints_weights_complex.gltf": "Complex joints/weights data check"
"joints_weights_complex.gltf": "Complex joints/weights data check",
"joints_no_weights.gltf": "Missing weights data"
}
},
"node": {
Expand Down
76 changes: 76 additions & 0 deletions test/base/data/mesh_data/joints_no_weights.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"asset": {
"version": "2.0"
},
"nodes": [
{},
{
"mesh": 0,
"skin": 0
}
],
"skins": [
{
"joints": [0]
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"POSITION": 0,
"JOINTS_0": 1,
"WEIGHTS_0": 2
},
"mode": 0
}
]
}
],
"accessors": [
{
"type": "VEC3",
"componentType": 5126,
"count": 1,
"min": [
-1.0,
-1.0,
-1.0
],
"max": [
1.0,
1.0,
1.0
]
},
{
"type": "VEC4",
"componentType": 5121,
"count": 1,
"bufferView": 0,
"byteOffset": 12
},
{
"type": "VEC4",
"componentType": 5126,
"count": 1,
"bufferView": 0,
"byteOffset": 16
}
],
"bufferViews": [
{
"buffer": 0,
"byteLength": 32,
"byteStride": 32,
"target": 34962
}
],
"buffers": [
{
"byteLength": 16,
"uri": "data:application/octet-stream;base64,AAAAAAAAAAAAAAAAAAAAAA=="
}
]
}
49 changes: 49 additions & 0 deletions test/base/data/mesh_data/joints_no_weights.gltf.report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"uri": "test/base/data/mesh_data/joints_no_weights.gltf",
"mimeType": "model/gltf+json",
"validatorVersion": "2.0.0-dev.3.10",
"issues": {
"numErrors": 1,
"numWarnings": 0,
"numInfos": 1,
"numHints": 0,
"messages": [
{
"code": "BUFFER_VIEW_TOO_LONG",
"message": "BufferView does not fit buffer (0) byteLength (16).",
"severity": 0,
"pointer": "/bufferViews/0/byteLength"
},
{
"code": "UNUSED_OBJECT",
"message": "This object may be unused.",
"severity": 2,
"pointer": "/nodes/1"
}
],
"truncated": false
},
"info": {
"version": "2.0",
"resources": [
{
"pointer": "/buffers/0",
"mimeType": "application/gltf-buffer",
"storage": "data-uri",
"byteLength": 16
}
],
"animationCount": 0,
"materialCount": 0,
"hasMorphTargets": false,
"hasSkins": true,
"hasTextures": false,
"hasDefaultScene": false,
"drawCallCount": 1,
"totalVertexCount": 1,
"totalTriangleCount": 0,
"maxUVs": 0,
"maxInfluences": 4,
"maxAttributes": 3
}
}

0 comments on commit 0cdee26

Please sign in to comment.