Skip to content

Commit f74918d

Browse files
marklundinCopilot
andauthored
Fix Environment Cleanup (#219)
* fix(Environment): add null checks for scene properties before resetting values - Added null checks for app.scene.skybox and app.scene.envAtlas to prevent potential errors during cleanup. - Wrapped scene reset logic in a conditional to ensure app.scene exists before attempting to modify its properties. * fix(Environment): improve cleanup process - Added a changeset to address an issue with Environment cleanup in the @playcanvas/react package. - Ensures proper handling during environment reset to prevent potential errors. * Update packages/lib/src/components/Environment.tsx Co-authored-by: Copilot <[email protected]> * Update packages/lib/src/components/Environment.tsx Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent f1622bb commit f74918d

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

.changeset/eleven-crabs-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@playcanvas/react": patch
3+
---
4+
5+
Fixes issue with Environment cleanup

packages/lib/src/components/Environment.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ function Environment(props: EnvironmentProps) {
7878
app.scene.skybox = skybox;
7979

8080
return () => {
81-
app.scene.skybox = null;
81+
if (app?.scene) {
82+
app.scene.skybox = null;
83+
}
8284
};
8385
}, [appHasEnvironment.current, safeSceneProps.skybox?.id]);
8486

@@ -93,7 +95,9 @@ function Environment(props: EnvironmentProps) {
9395
app.scene.envAtlas = safeSceneProps?.envAtlas?.resource as Texture ?? null;
9496

9597
return () => {
96-
app.scene.envAtlas = null;
98+
if (app?.scene) {
99+
app.scene.envAtlas = null;
100+
}
97101
};
98102
}, [appHasEnvironment.current, safeSceneProps.envAtlas?.id]);
99103

@@ -140,17 +144,19 @@ function Environment(props: EnvironmentProps) {
140144
* TODO: Find a better way to reset the scene and sky.
141145
*/
142146

143-
app.scene.exposure = 1;
144-
app.scene.skyboxRotation = new Quat().setFromEulerAngles(0, 0, 0);
145-
app.scene.sky.node.setLocalScale(1, 1, 1);
146-
app.scene.sky.node.setLocalPosition(0, 0, 0);
147-
app.scene.sky.center.set(0, 0.05, 0);
148-
app.scene.sky.type = SKYTYPE_INFINITE;
149-
app.scene.sky.depthWrite = false;
150-
app.scene.skyboxMip = 0;
151-
app.scene.skyboxLuminance = 0;
152-
app.scene.skyboxIntensity = 1;
153-
app.scene.skyboxHighlightMultiplier = 1;
147+
if (app.scene) {
148+
app.scene.exposure = 1;
149+
app.scene.skyboxRotation = new Quat().setFromEulerAngles(0, 0, 0);
150+
app.scene.sky.node.setLocalScale(1, 1, 1);
151+
app.scene.sky.node.setLocalPosition(0, 0, 0);
152+
app.scene.sky.center.set(0, 0.05, 0);
153+
app.scene.sky.type = SKYTYPE_INFINITE;
154+
app.scene.sky.depthWrite = false;
155+
app.scene.skyboxMip = 0;
156+
app.scene.skyboxLuminance = 0;
157+
app.scene.skyboxIntensity = 1;
158+
app.scene.skyboxHighlightMultiplier = 1;
159+
}
154160
};
155161

156162
}, [

0 commit comments

Comments
 (0)