Skip to content

Conversation

@kevinmoran
Copy link

When fetching data from an accessor there is this common code:

const uint8_t* element = cgltf_buffer_view_data(accessor->buffer_view);
if (element == NULL)
{
	return 0;
}
element += accessor->offset;

I propose adding a helper function cgltf_accessor_data() to reduce this boilerplate - I actually had a hidden bug in my code because I was not checking if buffer view data was null before adding accessor offset, so I think it's worthwhile even if it adds an extra null check.

I ran python test_all.py with no errors.

@kevinmoran
Copy link
Author

Technically a similar helper could be added for fetching data from sparse accessors (e.g. in cgltf_find_sparse_index()), but because there's 2 buffers (indices and values) it would be uglier - either 2 separate functions or passing the return pointers as arguments. I haven't had to use sparse accessors so I don't think I'm qualified to weigh in on what would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant