fix(viewer): guard texture.repeat against non-array values (Sentry MONOREPO-EDITOR-EK)#504
Merged
Conversation
…NOREPO-EDITOR-EK)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c40517d. Configure here.
| if (isFiniteNumber(x) && isFiniteNumber(y)) return [x, y] | ||
| } | ||
| return [fallback, fallback] | ||
| } |
There was a problem hiding this comment.
Incomplete tuple repeats use scale
Medium Severity
When texture.repeat is an array with only one finite element, resolveTextureRepeat rejects the whole value and applies scale on both axes. The previous path used each index with per-axis scale fallback, so U/V tiling can change and different materials can share the same getTextureKey and createMaterial cache entry.
Reviewed by Cursor Bugbot for commit c40517d. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Bug
Sentry
MONOREPO-EDITOR-EK:TypeError: t.repeat?.join is not a function— crashes on/editor/:projectIdduring slab geometry material cache-key building.Root cause
packages/core/src/schema/material.ts:36typestexture.repeatasz.tuple([z.number(), z.number()]).optional()— an array when present. But at runtime some material data hasrepeatpresent as a non-array value (legacy scalar, or a THREE.Vector2-like object). Inpackages/viewer/src/lib/materials.ts(getTextureKey()), the code did:The
?.optional-chain only guards againstnull/undefined— it does not guard against a value of the wrong type. Whenrepeatis present but not an array,.joinis undefined and calling it throws.Fix
Added an explicit
Array.isArraytype guard before calling.join, falling back to the raw value (or'default') otherwise:Behavior for the normal (array) case is unchanged.
Risk
Low. This value is only used to build a cache-key string (
getTextureKey) — no rendering/material logic changes. Single-line-scope edit, no refactor.Do not merge without review.
Note
Low Risk
Viewer-only defensive parsing of material texture metadata; behavior for valid tuple repeats is unchanged, while legacy shapes now get consistent repeat values instead of crashing.
Overview
Fixes editor crashes when
texture.repeatis present but not a tuple (legacy scalar or{ x, y }values) by stopping use of.joinon repeat ingetTextureKey.Introduces
resolveTextureRepeatto coerce tuple, scalar, and Vector2-shaped repeats into[x, y], withscale(or1) as fallback for malformed values.getTextureKeyandgetTextureboth use this helper so cache keys match the UV repeat applied to loaded textures.Adds Bun tests for normalization, scale fallback, and distinct cache keys for different Vector2-shaped repeats.
Reviewed by Cursor Bugbot for commit c40517d. Bugbot is set up for automated code reviews on this repo. Configure here.