diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-08 14:32:05 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-08 14:32:05 +0100 |
| commit | a982cbc11b6a542320f7951ecb286a2e7522e7c8 (patch) | |
| tree | 99324cefbb1c39f83675f79485ba84a6f5633808 | |
| parent | de2e997de3edb032645bc6c1aecbbeaa28cc9a50 (diff) | |
fix: Correct offset management in scene_loader.cc for plane_distance
| -rw-r--r-- | src/3d/scene_loader.cc | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/3d/scene_loader.cc b/src/3d/scene_loader.cc index 63daaa0..6da8213 100644 --- a/src/3d/scene_loader.cc +++ b/src/3d/scene_loader.cc @@ -74,25 +74,27 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { offset += 4; vec3 scale(sx, sy, sz); - float cr = *reinterpret_cast<const float*>(data + offset); - offset += 4; - float cg = *reinterpret_cast<const float*>(data + offset); - offset += 4; - float cb = *reinterpret_cast<const float*>(data + offset); - offset += 4; + // Color components (cr, cg, cb, ca) + float cr = *reinterpret_cast<const float*>(data + offset); offset += 4; + float cg = *reinterpret_cast<const float*>(data + offset); offset += 4; + float cb = *reinterpret_cast<const float*>(data + offset); offset += 4; + // Read ca, advance offset AFTER reading ca, then construct color + float ca = *reinterpret_cast<const float*>(data + offset); offset += 4; // Offset is now after ca vec4 color(cr, cg, cb, ca); // Plane Distance (if type == PLANE) float plane_distance = 0.0f; if (type == ObjectType::PLANE) { + // Check bounds before reading plane_distance if (offset + 4 > size) return false; plane_distance = *reinterpret_cast<const float*>(data + offset); - offset += 4; + offset += 4; // Advance offset after reading plane_distance } // Mesh Asset Name Length - if (offset + 4 > size) - return false; + // The offset is now correctly positioned for name_len, + // either after ca (if not PLANE) or after plane_distance (if PLANE). + if (offset + 4 > size) return false; uint32_t name_len = *reinterpret_cast<const uint32_t*>(data + offset); offset += 4; |
