mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:47:46 +00:00
GLTeapot: Adds additional error checking when loading files
- If the 3D file contains no vertices then an error is raised - If the file is not an OBJ file then an error is raised
This commit is contained in:
parent
01a5ffdae0
commit
d9dc42fab5
2 changed files with 19 additions and 2 deletions
|
@ -66,6 +66,11 @@ RefPtr<Mesh> WavefrontOBJLoader::load(const String& fname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (vertices.is_empty()) {
|
||||||
|
dbgln("Wavefront: Failed to read any data from 3D file: {}", fname);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
dbgln("Wavefront: Done.");
|
dbgln("Wavefront: Done.");
|
||||||
return adopt_ref(*new Mesh(vertices, triangles));
|
return adopt_ref(*new Mesh(vertices, triangles));
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,6 +102,7 @@ void GLContextWidget::timer_event(Core::TimerEvent&)
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadMatrixf((float*)matrix.elements());
|
glLoadMatrixf((float*)matrix.elements());
|
||||||
|
|
||||||
|
if (!m_mesh.is_null())
|
||||||
m_mesh->draw();
|
m_mesh->draw();
|
||||||
|
|
||||||
m_context->present();
|
m_context->present();
|
||||||
|
@ -111,7 +112,12 @@ void GLContextWidget::timer_event(Core::TimerEvent&)
|
||||||
bool GLContextWidget::load(const String& fname)
|
bool GLContextWidget::load(const String& fname)
|
||||||
{
|
{
|
||||||
m_mesh = m_mesh_loader->load(fname);
|
m_mesh = m_mesh_loader->load(fname);
|
||||||
return !m_mesh.is_null();
|
if (!m_mesh.is_null()) {
|
||||||
|
dbgln("GLTeapot: mesh has {} triangles.", m_mesh->triangle_count());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -159,6 +165,12 @@ int main(int argc, char** argv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto file = Core::File::construct(open_path.value());
|
auto file = Core::File::construct(open_path.value());
|
||||||
|
|
||||||
|
if (!file->filename().ends_with(".obj")) {
|
||||||
|
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: invalid file type", open_path.value()), "Error", GUI::MessageBox::Type::Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!file->open(Core::OpenMode::ReadOnly) && file->error() != ENOENT) {
|
if (!file->open(Core::OpenMode::ReadOnly) && file->error() != ENOENT) {
|
||||||
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", open_path.value(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);
|
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", open_path.value(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue