mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-07 07:09:06 +08:00
Fix bug in admesh code that causes random binary STL files not to be read correctly on Windows. #2461
This commit is contained in:
parent
3b09377a43
commit
504cbd89db
@ -77,8 +77,8 @@ stl_count_facets(stl_file *stl, char *file) {
|
|||||||
|
|
||||||
if (stl->error) return;
|
if (stl->error) return;
|
||||||
|
|
||||||
/* Open the file */
|
/* Open the file in binary mode first */
|
||||||
stl->fp = fopen(file, "r");
|
stl->fp = fopen(file, "rb");
|
||||||
if(stl->fp == NULL) {
|
if(stl->fp == NULL) {
|
||||||
error_msg = (char*)
|
error_msg = (char*)
|
||||||
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
malloc(81 + strlen(file)); /* Allow 80 chars+file size for message */
|
||||||
@ -104,9 +104,6 @@ stl_count_facets(stl_file *stl, char *file) {
|
|||||||
for(s = 0; s < sizeof(chtest); s++) {
|
for(s = 0; s < sizeof(chtest); s++) {
|
||||||
if(chtest[s] > 127) {
|
if(chtest[s] > 127) {
|
||||||
stl->stats.type = binary;
|
stl->stats.type = binary;
|
||||||
/* close and reopen with binary flag (needed on Windows) */
|
|
||||||
fclose(stl->fp);
|
|
||||||
stl->fp = fopen(file, "rb");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,6 +134,9 @@ stl_count_facets(stl_file *stl, char *file) {
|
|||||||
}
|
}
|
||||||
/* Otherwise, if the .STL file is ASCII, then do the following */
|
/* Otherwise, if the .STL file is ASCII, then do the following */
|
||||||
else {
|
else {
|
||||||
|
/* Reopen the file in text mode (for getting correct newlines on Windows) */
|
||||||
|
freopen(file, "r", stl->fp);
|
||||||
|
|
||||||
/* Find the number of facets */
|
/* Find the number of facets */
|
||||||
j = 0;
|
j = 0;
|
||||||
for(i = 0; i < file_size ; i++) {
|
for(i = 0; i < file_size ; i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user