Merge pull request #173 from pps83/master

fix for #108 and workaround to avoid crash in #171
This commit is contained in:
FrankGalligan 2017-08-07 10:05:40 -07:00 committed by GitHub
commit 2049e1a089
5 changed files with 8 additions and 6 deletions

View File

@ -64,7 +64,7 @@ class MeshPredictionSchemeTexCoordsPortableDecoder
}
bool SetParentAttribute(const PointAttribute *att) override {
if (att->attribute_type() != GeometryAttribute::POSITION)
if (!att || att->attribute_type() != GeometryAttribute::POSITION)
return false; // Invalid attribute type.
if (att->num_components() != 3)
return false; // Currently works only for 3 component positions.

View File

@ -59,7 +59,7 @@ const PointAttribute *SequentialAttributeDecoder::GetPortableAttribute() {
// If needed, copy point to attribute value index mapping from the final
// attribute to the portable attribute.
if (!attribute_->is_mapping_identity() &&
portable_attribute_->is_mapping_identity()) {
portable_attribute_ && portable_attribute_->is_mapping_identity()) {
portable_attribute_->SetExplicitMapping(attribute_->indices_map_size());
for (PointIndex i(0); i < attribute_->indices_map_size(); ++i) {
portable_attribute_->SetPointMapEntry(i, attribute_->mapped_index(i));

View File

@ -31,7 +31,8 @@ std::unique_ptr<Mesh> ReadMeshFromFile(const std::string &file_name,
std::unique_ptr<Mesh> mesh(new Mesh());
// Analyze file extension.
const std::string extension =
parser::ToLower(file_name.substr(file_name.size() - 4));
parser::ToLower(file_name.size() >= 4 ?
file_name.substr(file_name.size() - 4) : file_name);
if (extension == ".obj") {
// Wavefront OBJ file format.
ObjDecoder obj_decoder;

View File

@ -25,7 +25,8 @@ std::unique_ptr<PointCloud> ReadPointCloudFromFile(
const std::string &file_name) {
std::unique_ptr<PointCloud> pc(new PointCloud());
// Analyze file extension.
const std::string extension = file_name.substr(file_name.size() - 4);
const std::string extension = file_name.size() >= 4 ?
file_name.substr(file_name.size() - 4) : file_name;
if (extension == ".obj") {
// Wavefront OBJ file format.
ObjDecoder obj_decoder;

View File

@ -134,8 +134,8 @@ int main(int argc, char **argv) {
// Save the decoded geometry into a file.
// TODO(ostava): Currently only .ply and .obj are supported.
const std::string extension =
options.output.substr(options.output.size() - 4);
const std::string extension = options.output.size() >= 4 ?
options.output.substr(options.output.size() - 4) : options.output;
if (extension == ".obj") {
draco::ObjEncoder obj_encoder;
if (mesh) {