summaryrefslogtreecommitdiff
path: root/src/3d/scene_loader.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/3d/scene_loader.cc')
-rw-r--r--src/3d/scene_loader.cc20
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;