]> git.sur5r.net Git - fstl/blob - src/loader.cpp
Added check for stl corruption
[fstl] / src / loader.cpp
1 #include "loader.h"
2 #include "mesh.h"
3
4 Loader::Loader(QObject* parent, const QString& filename)
5     : QThread(parent), filename(filename)
6 {
7     // Nothing to do here
8 }
9
10 void Loader::run()
11 {
12     {   // Verify that this isn't an ascii stl file
13         QFile file(filename);
14         file.open(QIODevice::ReadOnly);
15         if (file.read(5) == "solid")
16         {
17             emit error_ascii_stl();
18             return;
19         }
20
21         // Skip the rest of the buffer
22         file.read(75);
23
24         // Assume we're on a little-endian system for simplicity
25         uint32_t tri_count;
26         file.read(reinterpret_cast<char*>(&tri_count), sizeof(tri_count));
27
28         if (file.size() != 84 + tri_count*50)
29         {
30             emit error_bad_stl();
31             return;
32         }
33     }
34
35     emit got_mesh(Mesh::load_stl(filename));
36     emit loaded_file(filename);
37 }