TIL that std::vector<bool> is a bit field

https://howardhinnant.github.io/onvectorbool.html
This commit is contained in:
sabrina-shanman 2019-09-10 16:31:30 -07:00
parent 384b7fd629
commit 65d85138cc
2 changed files with 9 additions and 8 deletions

View file

@ -246,11 +246,10 @@ void ModelBaker::bakeSourceCopy() {
// Begin hfm baking
baker.run();
for (auto error : baker.getDracoErrors()) {
if (error) {
handleError("Failed to finalize the baking of a draco Geometry node from model " + _modelURL.toString());
return;
}
const auto& errors = baker.getDracoErrors();
if (std::find(errors.cbegin(), errors.cend(), true) != errors.cend()) {
handleError("Failed to finalize the baking of a draco Geometry node from model " + _modelURL.toString());
return;
}
_hfmModel = baker.getHFMModel();

View file

@ -222,21 +222,23 @@ void BuildDracoMeshTask::run(const baker::BakeContextPointer& context, const Inp
auto& materialLists = output.edit2();
dracoBytesPerMesh.reserve(meshes.size());
dracoErrorsPerMesh.reserve(meshes.size());
// vector<bool> is an exception to the std::vector conventions as it is a bit field
// So a bool reference to an element doesn't work
dracoErrorsPerMesh.resize(meshes.size());
materialLists.reserve(meshes.size());
for (size_t i = 0; i < meshes.size(); i++) {
const auto& mesh = meshes[i];
const auto& normals = baker::safeGet(normalsPerMesh, i);
const auto& tangents = baker::safeGet(tangentsPerMesh, i);
dracoBytesPerMesh.emplace_back();
dracoErrorsPerMesh.emplace_back();
auto& dracoBytes = dracoBytesPerMesh.back();
auto& dracoError = dracoErrorsPerMesh.back();
materialLists.push_back(createMaterialList(mesh));
const auto& materialList = materialLists.back();
bool dracoError;
std::unique_ptr<draco::Mesh> dracoMesh;
std::tie(dracoMesh, dracoError) = createDracoMesh(mesh, normals, tangents, materialList);
dracoErrorsPerMesh[dracoErrorsPerMesh.size()-1] = dracoError;
if (dracoMesh) {
draco::Encoder encoder;