mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-01 03:12:04 +08:00
Fix issue with missing last trinagle in obj file:
https://github.com/prusa3d/PrusaSlicer/issues/12157 reincarnation of SPE-2129
This commit is contained in:
parent
d020d6e3a0
commit
e02d273816
@ -354,11 +354,20 @@ bool objparse(const char *path, ObjData &data)
|
|||||||
if (pFile == 0)
|
if (pFile == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
constexpr size_t half_buf = 65536;
|
||||||
try {
|
try {
|
||||||
char buf[65536 * 2];
|
char buf[half_buf * 2];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
size_t lenPrev = 0;
|
size_t lenPrev = 0;
|
||||||
while ((len = ::fread(buf + lenPrev, 1, 65536, pFile)) != 0) {
|
while ((len = ::fread(buf + lenPrev, 1, half_buf-1, pFile)) != 0) {
|
||||||
|
if (std::feof(pFile)) {
|
||||||
|
// Fix issue with missing last trinagle in obj file:
|
||||||
|
// https://github.com/prusa3d/PrusaSlicer/issues/12157
|
||||||
|
// algorithm expect line endings after last face
|
||||||
|
// but file format support it
|
||||||
|
buf[len+lenPrev] = '\n';
|
||||||
|
++len;
|
||||||
|
}
|
||||||
len += lenPrev;
|
len += lenPrev;
|
||||||
size_t lastLine = 0;
|
size_t lastLine = 0;
|
||||||
for (size_t i = 0; i < len; ++ i)
|
for (size_t i = 0; i < len; ++ i)
|
||||||
@ -373,7 +382,7 @@ bool objparse(const char *path, ObjData &data)
|
|||||||
lastLine = i + 1;
|
lastLine = i + 1;
|
||||||
}
|
}
|
||||||
lenPrev = len - lastLine;
|
lenPrev = len - lastLine;
|
||||||
if (lenPrev > 65536) {
|
if (lenPrev > half_buf) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "ObjParser: Excessive line length";
|
BOOST_LOG_TRIVIAL(error) << "ObjParser: Excessive line length";
|
||||||
::fclose(pFile);
|
::fclose(pFile);
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user