summaryrefslogtreecommitdiff
path: root/themes/src/renderer_3d.cpp
diff options
context:
space:
mode:
authorMatt Kosarek <matt.kosarek@canonical.com>2026-07-08 09:19:53 -0400
committerMatt Kosarek <matt.kosarek@canonical.com>2026-07-08 09:19:53 -0400
commit2edd21e184b16a2a933aa406255900592163514d (patch)
treeb70bea20f007adcc41b4519779ad9012173906d2 /themes/src/renderer_3d.cpp
parent18f91174078809fa9ed61a0548515803367b55ad (diff)
bugfix: bunny broken
Diffstat (limited to 'themes/src/renderer_3d.cpp')
-rw-r--r--themes/src/renderer_3d.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/themes/src/renderer_3d.cpp b/themes/src/renderer_3d.cpp
index cc79940..5ba0fb6 100644
--- a/themes/src/renderer_3d.cpp
+++ b/themes/src/renderer_3d.cpp
@@ -81,7 +81,7 @@ struct LineItem {
};
inline i32 readPastSpaces(i32 i, const char* content) {
- while (content[i] == ' ') i++;
+ while (content[i] == ' ' || content[i] == '\t' || content[i] == '\r') i++;
return i;
}
@@ -93,7 +93,7 @@ inline i32 readPastLine(i32 i, const char* content) {
inline i32 readToken(i32 i, const char* content, char* output) {
i32 tidx = 0;
i = readPastSpaces(i, content);
- while (content[i] != ' ' && content[i] != '\n' && content[i] != '\0') {
+ while (content[i] != ' ' && content[i] != '\t' && content[i] != '\r' && content[i] != '\n' && content[i] != '\0') {
output[tidx] = content[i];
i++;
tidx++;
@@ -143,11 +143,16 @@ Mesh3d Mesh3d_fromObj(Renderer3d* renderer, const char* content, const i32 len)
i = readToken(i, content, buffer);
break;
case LineType_v: {
- while (content[i] != '\n' && content[i] != '\0') {
+ // Bound to 3 components: OBJ lines may carry trailing tokens (e.g. a
+ // stray "\r" from CRLF files, or a 4th vertex weight), and the union
+ // only holds 3 slots — writing past it corrupts the stack.
+ while (content[i] != '\n' && content[i] != '\r' && content[i] != '\0' && lt.idx < 3) {
i = readToken(i, content, buffer);
+ if (buffer[0] == '\0') break;
lt.v.vertices[lt.idx] = atof(buffer);
lt.idx++;
}
+ i = readPastLine(i, content);
float fColor = randomFloatBetween(0.8, 1);
result.vertices.add({
@@ -157,12 +162,15 @@ Mesh3d Mesh3d_fromObj(Renderer3d* renderer, const char* content, const i32 len)
break;
}
case LineType_f: {
- while (content[i] != '\n' && content[i] != '\0') {
+ // Same bound as vertices: only the first 3 indices fit the union.
+ while (content[i] != '\n' && content[i] != '\r' && content[i] != '\0' && lt.idx < 3) {
i = readToken(i, content, buffer);
+ if (buffer[0] == '\0') break;
lt.v.indices[lt.idx] = atoi(buffer);
lt.idx++;
}
-
+ i = readPastLine(i, content);
+
auto v1idx = lt.v.indices[0] - 1;
auto v2idx = lt.v.indices[1] - 1;
auto v3idx = lt.v.indices[2] - 1;