raylib::Model Causing a Malloc error on Copy
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Start by reproducing the std::variant, std::map, and std::vector examples with raylib::Model, then inspect raylib::Model's copy and destruction behavior against the raw Model cases. Done means these container cases close without invalid-free errors while preserving the successful raw raylib behavior.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hey guys!
I've run into a segfault that only seems to be caused by the destructor of both raylib::Model and raylib::Texture. I'm not sure where the full issue actually lies, however I thought I'd make it known here.
The context here is that I'm trying to build a resource manager that stores and tracks all Models and Textures that were loaded into the project. To allow multiple different types of objects, I'm using a std::variant class to store either a texture or Model, with a string acting as the key. The data structure is as follows:
std::map<std::string, std::variant<raylib::Model, raylib::Texture2D>>
The issue is, once I insert an element to this map, my program crashes with the following error:
app(31394,0x10fc30e00) malloc: *** error for object 0x7f9100000000: pointer being freed was not allocated
app(31394,0x10fc30e00) malloc: *** set a breakpoint in malloc_error_break to debug
make: *** [execute] Abort trap: 6
To test this further, I set up a few test cases to see whether I could isolate this issue. Here's my code for storing a standard Raylib Model is a std::variant class:
auto model = LoadModel("assets/models/cube/cube.obj");
std::variant<Model, Texture> variant = std::variant<Model, Texture>();
variant = model;
When running this, I get no issues and the program runs normally. I can even add this variant to a map with no issue:
std::map<std::string, std::variant<Model, Texture>> map = std::map<std::string, std::variant<Model, Texture>>();
map.insert({"model", variant});
Doing this has no issues at all with any part of the program. It runs correctly and closes correctly.
When trying the same tests with raylib::Model, I get a very different outcome:
raylib::Model model2 = raylib::Model("assets/models/cube/cube.obj");
std::variant<raylib::Model, raylib::Texture> variant2 = std::variant<raylib::Model, raylib::Texture>(model2);
Running the following causes no errors initially, however closing the program results in the following segfault:
app(31580,0x1115eae00) malloc: *** error for object 0x9000000000000000: pointer being freed was not allocated
app(31580,0x1115eae00) malloc: *** set a breakpoint in malloc_error_break to debug
make: *** [execute] Abort trap: 6
When I then try and add the variant to a map of variants:
std::map<std::string, std::variant<raylib::Model, raylib::Texture>> map = std::map<std::string, std::variant<raylib::Model, raylib::Texture>>();
map.insert({"variant", variant});
This causes an instant error:
INFO: MODEL: model has 1 material meshes
INFO: VAO: [ID 2] Mesh uploaded successfully to VRAM (GPU)
INFO: VAO: [ID 2] Unloaded vertex data from VRAM (GPU)
INFO: MODEL: Unloaded model from RAM and VRAM
app(31580,0x1115eae00) malloc: *** error for object 0x9000000000000000: pointer being freed was not allocated
app(31580,0x1115eae00) malloc: *** set a breakpoint in malloc_error_break to debug
make: *** [execute] Abort trap: 6
I'll also note that this issue seems to persist whenever a raylib::Model is added to any container type. For example:
std::vector<raylib::Model> vector = std::vector<raylib::Model>();
vector.push_back(raylib::Model("assets/models/cube/cube.obj"));
This will run alright, but when the application is closed another crash will occur:
app(31634,0x11b0fee00) malloc: *** error for object 0x7ffedfe0b918: pointer being freed was not allocated
app(31634,0x11b0fee00) malloc: *** set a breakpoint in malloc_error_break to debug
make: *** [execute] Abort trap: 6
The reason why I made all these cases was to try and illustrate that there seems to be some sort of issue with the way the raylib::Model class is being destroyed. Looking over Raylib's logs, I can see the following sequence of events:
INFO: MODEL: [assets/models/cube/cube.obj] OBJ data loaded successfully: 1 meshes / 1 materials
INFO: MODEL: model has 1 material meshes
INFO: VAO: [ID 2] Mesh uploaded successfully to VRAM (GPU)
INFO: VAO: [ID 2] Unloaded vertex data from VRAM (GPU)
INFO: MODEL: Unloaded model from RAM and VRAM
Looking at this, it appears as if the model is being loaded in successfully, but is immediately being unloaded as soon as the model is added to a container. I'm not sure why this is the case, however I assume it might have to do with how the model is copied?
I'm not convinced that this is an issue with the normal raylib library, since these issues don't seem to be persisting with traditional raylib objects. Would you happen to have any insights into this?
- Ngôn ngữ chính
- C++
- Star
- 965
- Fork
- 120
- Merge trung bình
- 1 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của RobLoach/raylib-cpp
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
RobLoach/raylib-cpp#425 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
RobLoach/raylib-cpp#427 ·
-
Code genĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
RobLoach/raylib-cpp#415 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
RobLoach/raylib-cpp#370 · 1 bình luận ·
-
SDF Font SupportĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
RobLoach/raylib-cpp#366 · 3 bình luận ·
Tất cả issue của RobLoach/raylib-cpp
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
MerginMaps/mobile#4741 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ros-perception/image_pipeline#1198 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Icinga/icinga2#11077 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
CVE PCRE2 - CVE-2026-103111Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
pocoproject/poco#5515 ·
Maintainer thường phản hồi trong vòng 2 ngày