Skip to content

Commit a1fe3dc

Browse files
author
CubeCoders
committed
Fix #7: DirectionalLight lazy-initialises trig tables so construction order vs Scene doesn't matter
1 parent 4b5cd52 commit a1fe3dc

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/Light.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ void DirectionalLight::updateDirection(Vector3 newDirection) {
1515
}
1616

1717
void DirectionalLight::calculateLightDirection() {
18+
// The trig tables are normally initialised by Scene::Scene(), but
19+
// a DirectionalLight can be constructed before any Scene exists (e.g.
20+
// as a struct member alongside a Scene*). Guard against that here so
21+
// worldLightDir is always valid regardless of construction order.
22+
if (sin_table[90] == 0) initializeTrigTables();
1823
int32_t azimuthDeg = (direction.x + ANGLE_MAX) % ANGLE_MAX; // Keep within 0-359 range
1924
int32_t elevationDeg = (direction.y + ANGLE_MAX) % ANGLE_MAX; // Ignore direction.z
2025

0 commit comments

Comments
 (0)