Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEGV when iterating .gltf primitive indicied accessor via iterateAccessor or iterateAccessorWithIndex #45

Closed
morgankdavis opened this issue Jan 29, 2024 · 4 comments
Labels
done Everything has been addressed question Further information is requested

Comments

@morgankdavis
Copy link

See the attached test scene.
pineapple_only.zip

Load and parse the scene and try to iterate over the first primitive's indicesAccessor using iterateAccessor() or iterateAccessorWithIndex(). For example:

`
fastgltf::Asset& asset // exists
fastgltf::Primitive& primitive // exists

if (auto indiciesAccessorIndex = primitive.indicesAccessor) {

	vector<uint32_t> indices;
	if (primitive.indicesAccessor.has_value()) {
		auto &accessor = asset.accessors[*indiciesAccessorIndex];
		indices.resize(accessor.count);

		iterateAccessorWithIndex<uint32_t>(
				asset, accessor, [&](uint32_t index, size_t idx) {
					indices[idx] = index;
				});
	}
}

`

Observe SEGV at getAccessorElementAt(), case ComponentType::UnsignedShort.

Thanks! Awesome library!

@spnda
Copy link
Owner

spnda commented Jan 29, 2024

A SEGV in getAccessorElement leads me to believe the buffers aren't loaded and the code then tries to dereference a nullptr. Are you positive you either load buffers yourself or specify Options::LoadGLBBuffers and/or Options::LoadExternalBuffers?

Otherwise, do you have any more specific information when the exception occurs?

@morgankdavis
Copy link
Author

Failing to specify any options was the issue; that also explains problems I was having loading texture data. Thank you.

@spnda
Copy link
Owner

spnda commented Jan 30, 2024

I thought about this a bit over night. Would it perhaps make sense to add some sort of assert in debug mode that would have a message such as "Buffers are not loaded but required for the accessor tools" so that newer users who missed that part of the documentation that buffers and images aren't loaded by default would understand what the issue is much quicker? Or do you have any suggestions how to make this a bit more user friendly?

@spnda spnda added the question Further information is requested label Jan 30, 2024
@morgankdavis
Copy link
Author

I think an assert would be appropriate.

@spnda spnda added the done Everything has been addressed label Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done Everything has been addressed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants