Skip to content

Updating environment, additional dependencies, formatting, and optimizing imports#33

Merged
amyZepp merged 1 commit into
android:mainfrom
amyZepp:may_15_updates
May 15, 2026
Merged

Updating environment, additional dependencies, formatting, and optimizing imports#33
amyZepp merged 1 commit into
android:mainfrom
amyZepp:may_15_updates

Conversation

@amyZepp
Copy link
Copy Markdown
Contributor

@amyZepp amyZepp commented May 15, 2026

Updating environment, additional dependencies, formatting, and optimizing imports

@amyZepp amyZepp requested a review from fuentespatrick as a code owner May 15, 2026 23:21
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the kotlinx-coroutines-guava dependency, updates the material library version, and introduces skybox support in the EnvironmentController using ExrImage. Feedback was provided regarding the lifecycle management of pbrMaterial to ensure it is correctly tied to the xrSession, the performance impact of not caching ExrImage assets, and the implementation of safer casting when retrieving models from the asset cache to prevent potential exceptions.

// Create and apply a custom PBR material to the model when the XR session or target node changes.
LaunchedEffect(xrSession, bugdroidNode) {
val material = KhronosPbrMaterial.create(
val material = pbrMaterial ?: KhronosPbrMaterial.create(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The pbrMaterial is cached in a state that is not keyed to the xrSession. If the xrSession changes, this LaunchedEffect will restart and reuse the pbrMaterial from the previous session. Since KhronosPbrMaterial objects are tied to a specific session, reusing them across sessions is invalid and can lead to crashes or rendering issues. Ensure the pbrMaterial state is reset when the session changes (e.g., by using remember(xrSession) for its definition).

Comment on lines +53 to +56
val lightingForSkybox = ExrImage.createFromZip(
xrSession,
Paths.get("environments/green_hills_ibl.zip")
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ExrImage is recreated from the zip file every time the environment is changed. Unlike the GltfModel, this asset is not cached, which can lead to unnecessary I/O and processing overhead (unzipping and decoding) when switching between environments. Consider caching the ExrImage to improve performance.

xrSession,
Paths.get("environments/green_hills_ibl.zip")
)
val environmentModel = assetCache[environmentModelName] as GltfModel
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This forced cast to GltfModel will throw a NullPointerException if the asset has not been loaded into the assetCache yet (e.g., if the user triggers the environment change before the asynchronous loadModelAsset completes). While this is caught by the surrounding try-catch block, relying on exceptions for expected control flow is suboptimal. Consider using a safe cast and handling the missing asset explicitly.

Suggested change
val environmentModel = assetCache[environmentModelName] as GltfModel
val environmentModel = assetCache[environmentModelName] as? GltfModel ?: return@launch

@amyZepp amyZepp merged commit 2a2c3e9 into android:main May 15, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant