Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rmodels] tinyobj_loader_c.h fails to load .mtl if .obj uses \r\n as EOL #3473

Closed
SuperUserNameMan opened this issue Oct 27, 2023 · 4 comments

Comments

@SuperUserNameMan
Copy link
Contributor

SuperUserNameMan commented Oct 27, 2023

Hello,

Before redirecting me to open an issue on tinyobjloader-c, please note that the version of tinyobjloader-c used by Raylib is outdated, and it can't be directly updated because of API changes.

So, either rmodels.h needs to be updated alongside external/tinyobj_loader_c.h, either Raylib keeps the outdated version of tinyobj_loader_c.h and we have to fix it ourselves.


The bug :

Not sure if it's directly related to #3398, but i've just found a bug in the (outdated) version of tinyobj_loader_c.h used by Raylib regarding the end of lines format used in the .obj and .mtl files.

I'm on Linux, and I exported my .obj/.mtl from Wings3D which (unexpectedly) uses the MS-Windows' \r\n end of line format.

It appears that this version of tinyobj_loader_c.h does not handle \r\n correctly.

The filename sent to tinyobj_parse_and_index_mtl_file() from tinyobj_parse_obj() will contains a \r as the last character (before the \0), which prevents the .mtl file from loading.


The obvious workaround is to convert \r\n to \n in my .obj/.mtl files.


Edit : the quickfix i provided before this edit was not enough, there are other issues that leads to segfaults

@SuperUserNameMan
Copy link
Contributor Author

SuperUserNameMan commented Oct 27, 2023

Ok, here is a better quick fix to be inserted here :

/* Fill line infos. */
for (i = 0; i < end_idx; i++) {
if (is_line_ending(buf, i, end_idx)) {
line_infos[line_no].pos = prev_pos;
line_infos[line_no].len = i - prev_pos;
prev_pos = i + 1;
line_no++;
}
}


    /* Fill line infos. */
    for (i = 0; i < end_idx; i++) {
      if (is_line_ending(buf, i, end_idx)) {
        line_infos[line_no].pos = prev_pos;
        line_infos[line_no].len = i - prev_pos;

// ---- QUICK BUG FIX : https://github.com/raysan5/raylib/issues/3473
        if ( i > 0 && buf[i-1] == '\r' ) line_infos[line_no].len--; 
// --------

        prev_pos = i + 1;
        line_no++;
      }
    }

@raysan5
Copy link
Owner

raysan5 commented Oct 27, 2023

@SuperUserNameMan Actually, tinyfiledialogs-c library should be updated to latest stable version but in the meantime, feel free to send proposed fix as a PR for integration.

SuperUserNameMan added a commit to SuperUserNameMan/raylib that referenced this issue Oct 27, 2023
temporary quickfix for issue raysan5#3473
@SuperUserNameMan
Copy link
Contributor Author

@raysan5 : ok, done

raysan5 pushed a commit that referenced this issue Oct 27, 2023
temporary quickfix for issue #3473
@raysan5
Copy link
Owner

raysan5 commented Oct 27, 2023

@SuperUserNameMan Merged!

@raysan5 raysan5 closed this as completed Oct 27, 2023
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

No branches or pull requests

2 participants