loader_aw

Load OBJ/MTL file formats
git clone git://git.meso-star.fr/loader_aw.git
Log | Files | Refs | README | LICENSE

commit 879590fa7bfa1a0572bf2eaeebc085bf7c83058c
parent 02cf6fc192e1abbc4f1a50752df3741c686aa548
Author: vaplv <vaplv@free.fr>
Date:   Mon, 21 Jul 2014 18:51:05 +0200

Fix the `newline' character deletion in the mtl/obj streaming

Diffstat:
Msrc/aw_mtl.c | 5++++-
Msrc/aw_obj.c | 5++++-
Msrc/test_aw_mtl.c | 4++--
3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/aw_mtl.c b/src/aw_mtl.c @@ -580,6 +580,7 @@ aw_mtl_load_stream(struct aw_mtl* mtl, FILE* stream) mtl_clear(mtl); while((line = fgets (darray_char_data_get(&buf), (int)darray_char_size_get(&buf), stream))) { + size_t last_char; while(!strrchr(line,'\n')) { /* Ensure that the whole line was read */ if(darray_char_resize(&buf, darray_char_size_get(&buf) + buf_chunk)) { @@ -590,7 +591,9 @@ aw_mtl_load_stream(struct aw_mtl* mtl, FILE* stream) if(!fgets(line + strlen(line), (int)buf_chunk, stream)) /* EOF */ break; } - line[strlen(line) - 1] = '\0'; /* Remove the newline character */ + last_char = strlen(line) - 1; + if(line[last_char] == '\n') /* Remove the newline character */ + line[last_char] = '\0'; if(AW_OK != (res = parse_mtl_line(mtl, line))) goto error; diff --git a/src/aw_obj.c b/src/aw_obj.c @@ -595,6 +595,7 @@ aw_obj_load_stream(struct aw_obj* obj, FILE* stream) obj_clear(obj); while((line = fgets (darray_char_data_get(&buf), (int)darray_char_size_get(&buf), stream))) { + size_t last_char; while(!strrchr(line,'\n')) { /* Ensure that the whole line was read */ if(darray_char_resize(&buf, darray_char_size_get(&buf) + buf_chunk)) { @@ -605,7 +606,9 @@ aw_obj_load_stream(struct aw_obj* obj, FILE* stream) if(!fgets(line + strlen(line), (int)buf_chunk, stream)) /* EOF */ break; } - line[strlen(line) - 1] = '\0'; /* Remove the newline character */ + last_char = strlen(line) - 1; + if(line[last_char] == '\n') /* Remove the newline character */ + line[last_char] = '\0'; if(AW_OK != (res = parse_obj_line(obj, line))) goto error; diff --git a/src/test_aw_mtl.c b/src/test_aw_mtl.c @@ -28,9 +28,9 @@ test_common(struct aw_mtl* mtl) "map_d -s 1 1 1 -o 0 0 0 -mm 0 1 wisp.mps\n" "disp -s 1 1 .5 wisp.mps\n" "decal -s 1 1 1 -o 0 0 0 -mm 0 1 sand.mps\n" - "bump -s 1 1 1 -o 0 0 0 -bm 1 sand.mpb\n" + "refl -type sphere -mm 0 1 clouds.mpc\n" "\n" - "refl -type sphere -mm 0 1 clouds.mpc"; + "bump -s 1 1 1 -o 0 0 0 -bm 1 sand.mpb"; FILE* file; size_t nmtls; float tmp[3];