mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +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
Notes:
sideshowbarker
2024-07-18 17:47:04 +09:00
Author: https://github.com/ebiederstadt Commit: https://github.com/SerenityOS/serenity/commit/d9dc42fab5a Pull-request: https://github.com/SerenityOS/serenity/pull/7229 Reviewed-by: https://github.com/linusg
|
@ -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.");
|
||||
return adopt_ref(*new Mesh(vertices, triangles));
|
||||
}
|
||||
|
|
|
@ -102,7 +102,8 @@ void GLContextWidget::timer_event(Core::TimerEvent&)
|
|||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf((float*)matrix.elements());
|
||||
|
||||
m_mesh->draw();
|
||||
if (!m_mesh.is_null())
|
||||
m_mesh->draw();
|
||||
|
||||
m_context->present();
|
||||
update();
|
||||
|
@ -111,7 +112,12 @@ void GLContextWidget::timer_event(Core::TimerEvent&)
|
|||
bool GLContextWidget::load(const String& 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)
|
||||
|
@ -159,6 +165,12 @@ int main(int argc, char** argv)
|
|||
return;
|
||||
|
||||
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) {
|
||||
GUI::MessageBox::show(window, String::formatted("Opening \"{}\" failed: {}", open_path.value(), strerror(errno)), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue