Skip to content

Add Model(raylib::Mesh) constructor to throw an exception #305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/models/models_first_person_maze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main(void)

raylib::Image imMap("resources/cubicmap.png"); // Load cubicmap image (RAM)
raylib::Texture cubicmap(imMap); // Convert image to texture to display (VRAM)
raylib::MeshUnmanaged mesh = raylib::MeshUnmanaged::Cubicmap(imMap, Vector3{ 1.0f, 1.0f, 1.0f }); // Use MeshUnmanaged, Mesh will be handled by Model
raylib::MeshUnmanaged mesh = raylib::Mesh::Cubicmap(imMap, Vector3{ 1.0f, 1.0f, 1.0f }); // Use MeshUnmanaged, Mesh will be handled by Model
raylib::Model model(mesh);

// NOTE: By default each cube is mapped to one part of texture atlas
Expand Down
9 changes: 9 additions & 0 deletions include/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ class Model : public ::Model {
Load(mesh);
}

/*
* Overloaded constructor to catch when passing in a `raylib::Mesh`. It expects a `raylib::MeshUnmanaged or `::Mesh`.
*
* @throws raylib::RaylibException Since the model takes ownership of the Mesh, a `::Mesh` or `raylib::UnmanagedMesh` is required here.
*/
Model(const raylib::Mesh& mesh) {
throw raylib::RaylibException("Model(mesh) constructor expects a ::Mesh or raylib::MeshUnmanaged, as it takes ownership of the Mesh itself.");
}

~Model() {
Unload();
}
Expand Down