From 0f1cc05d59fd3a8d388a18256c1dfd42adf2e8f8 Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 29 Sep 2016 16:18:08 +0200 Subject: [PATCH 1/2] Bump version number to 0.3.2 --- CMakeLists.txt | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b8ded6..2dde660 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ include(CMakeDependentOption) project(gmio) set(GMIO_VERSION_MAJOR 0) set(GMIO_VERSION_MINOR 3) -set(GMIO_VERSION_PATCH 1) +set(GMIO_VERSION_PATCH 2) set(GMIO_VERSION ${GMIO_VERSION_MAJOR}.${GMIO_VERSION_MINOR}.${GMIO_VERSION_PATCH}) diff --git a/README.md b/README.md index 650f877..20bb877 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [![Coverage Status](https://coveralls.io/repos/fougue/gmio/badge.svg?branch=master&service=github)](https://coveralls.io/github/fougue/gmio?branch=master) [![License](https://img.shields.io/badge/license-BSD%202--clause-blue.svg)](https://github.com/fougue/gmio/blob/master/LICENSE.txt) -[![Version](https://img.shields.io/badge/version-v0.3.1-blue.svg?style=flat)](https://github.com/fougue/gmio/releases) +[![Version](https://img.shields.io/badge/version-v0.3.2-blue.svg?style=flat)](https://github.com/fougue/gmio/releases) C library for geometry input/output From a525eca31876b1f5d035999d49c9554e1729946c Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Thu, 29 Sep 2016 16:26:23 +0200 Subject: [PATCH 2/2] gmio_stl: fix ending error when reading multiple STL solids from stream This fixes GitHub issue #2 --- src/gmio_stl/internal/stla_infos_get.c | 19 ++++++++++++++++--- src/gmio_stl/stlb_read.c | 20 ++++++++++++++++---- tests/main_test_stl.c | 8 ++++---- tests/models/solid_4meshs.le_stlb | Bin 11820 -> 11736 bytes tests/test_stl_io.c | 8 +++++--- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/gmio_stl/internal/stla_infos_get.c b/src/gmio_stl/internal/stla_infos_get.c index 3ebaf32..316348d 100644 --- a/src/gmio_stl/internal/stla_infos_get.c +++ b/src/gmio_stl/internal/stla_infos_get.c @@ -183,13 +183,26 @@ int gmio_stla_infos_get( gmio_stringstream_skip_until_ascii_space(&sstream); } } - { /* Eat whole line */ + { + /* Eat whole line containing "endsolid" */ const char* c = gmio_stringstream_current_char(&sstream); while (c != NULL && *c != '\n' && *c != '\r') c = gmio_stringstream_next_char(&sstream); + /* Try to move stream pos on EOF or next solid */ + gmio_stringstream_skip_ascii_spaces(&sstream); + } + { + /* Whitespaces were just previously skipped, the stream pos can at + * either : + * - on EOF => fine, stream is exhausted + * - on some non-W/S => stream is then one char too far + * These two cases are detected by testing result of the + * stringstream's current char */ + const int end_offset = + gmio_stringstream_current_char(&sstream) != NULL ? 1 : 0; + infos->size -= sstream.strbuff_end - sstream.strbuff_at + end_offset; + infos->size = GMIO_MAX(0, infos->size); } - infos->size -= sstream.strbuff_end - sstream.strbuff_at; - infos->size = GMIO_MAX(0, infos->size); } return err; diff --git a/src/gmio_stl/stlb_read.c b/src/gmio_stl/stlb_read.c index d7f4bc0..44b709a 100644 --- a/src/gmio_stl/stlb_read.c +++ b/src/gmio_stl/stlb_read.c @@ -190,11 +190,23 @@ int gmio_stlb_read( gmio_task_iface_handle_progress(task, i_facet, total_facet_count); } /* end while */ - if (gmio_no_error(error)) + if (gmio_no_error(error)) { gmio_stl_mesh_creator_end_solid(mesh_creator); - - if (gmio_no_error(error) && i_facet != total_facet_count) - error = GMIO_STL_ERROR_FACET_COUNT; + if (i_facet != total_facet_count) { + error = GMIO_STL_ERROR_FACET_COUNT; + goto label_end; + } + /* Try to eat EOF by probing next byte in stream */ + if (!gmio_stream_at_end(stream)) { + struct gmio_streampos oldpos; + if (gmio_stream_get_pos(stream, &oldpos) == 0) { + uint8_t c; + gmio_stream_read_bytes(stream, &c, 1); + if (!gmio_stream_at_end(stream)) + gmio_stream_set_pos(stream, &oldpos); + } + } + } label_end: gmio_memblock_helper_release(&mblock_helper); diff --git a/tests/main_test_stl.c b/tests/main_test_stl.c index b252df2..af87ca7 100644 --- a/tests/main_test_stl.c +++ b/tests/main_test_stl.c @@ -50,6 +50,10 @@ const char* all_tests() gmio_memblock_set_default_constructor(gmio_memblock_for_tests); +#if 0 + generate_stlb_tests_models(); +#endif + UTEST_RUN(test_stl_coords_packing); UTEST_RUN(test_stl_triangle_packing); UTEST_RUN(test_stl_triangle_compute_normal); @@ -69,10 +73,6 @@ const char* all_tests() UTEST_RUN(test_stlb_header_str); UTEST_RUN(test_stlb_header_to_printable_str); -#if 0 - generate_stlb_tests_models(); -#endif - return NULL; } UTEST_MAIN(all_tests) diff --git a/tests/models/solid_4meshs.le_stlb b/tests/models/solid_4meshs.le_stlb index dfcb84544b7f615f52acc01d7c2ba2ac208132c3..14eacff77c733fb7e3d1c256d8ed1379ef0603ac 100644 GIT binary patch delta 7 OcmZ1zb0d1g4P5{bbOZ4K delta 14 WcmcZ+y(VVE4c*C?wOl7E@B;ujKn8{Y diff --git a/tests/test_stl_io.c b/tests/test_stl_io.c index 9b8f885..b95188a 100644 --- a/tests/test_stl_io.c +++ b/tests/test_stl_io.c @@ -34,9 +34,10 @@ #include "stl_utils.h" #include "../src/gmio_core/error.h" +#include "../src/gmio_core/internal/helper_stream.h" +#include "../src/gmio_core/internal/locale_utils.h" #include "../src/gmio_core/internal/min_max.h" #include "../src/gmio_core/internal/string.h" -#include "../src/gmio_core/internal/locale_utils.h" #include "../src/gmio_stl/stl_error.h" #include "../src/gmio_stl/stl_infos.h" #include "../src/gmio_stl/stl_io.h" @@ -333,12 +334,13 @@ static const char* __tstl__test_stl_read_multi_solid( struct gmio_stl_read_options roptions = {0}; struct gmio_stl_mesh_creator null_creator = {0}; roptions.func_stla_get_streamsize = gmio_stla_infos_get_streamsize; - while (gmio_no_error(error)) { + while (gmio_no_error(error) && !gmio_stream_at_end(&stream)) { error = gmio_stl_read(&stream, &null_creator, &roptions); if (gmio_no_error(error)) ++solid_count; } fclose(infile); + UTEST_ASSERT(gmio_no_error(error)); UTEST_COMPARE_UINT(expected_solid_count, solid_count); } else { @@ -434,7 +436,7 @@ static void generate_stlb_tests_models() struct gmio_stream ostream = gmio_stream_stdio(outfile); struct gmio_stl_read_options ropts = {0}; ropts.func_stla_get_streamsize = gmio_stla_infos_get_streamsize; - while (gmio_no_error(read_error)) { + while (gmio_no_error(read_error) && !gmio_stream_at_end(&istream)) { struct gmio_stl_data data = {0}; struct gmio_stl_mesh_creator creator = gmio_stl_data_mesh_creator(&data); struct gmio_stl_mesh mesh = {0};