Skip to content

ProjectionManager: the mode === null guard can never pass — OrthoPerspectiveCamera.mode throws when uninitialized, so projection.set() before world assignment throws instead of no-op #783

Description

@stokuewe

Versions

@thatopen/components 3.4.8 (verified against the published dist/index.mjs; source: packages/core/src/core/OrthoPerspectiveCamera/src/projections.ts + index.ts).

What happens

setOrthoCamera() opens with a guard written as a silent early return:

if (this._component.mode === null) return;

But mode is a getter that throws when _mode is unset:

get mode() {
  if (!this._mode) {
    throw new Error("Mode not found, camera not initialized");
  }
  return this._mode;
}

_mode is only populated in the camera's worlds.onItemSet handler, i.e. on world.camera = camera. So calling projection.set("Orthographic") (or toggle()) on a camera that has not been assigned to a world yet throws Error: Mode not found, camera not initialized out of a line whose intent is clearly a no-op. As written, the === null comparison is unreachable dead code.

Repro

const camera = new OBC.OrthoPerspectiveCamera(components);
await camera.projection.set("Orthographic"); // throws — expected: no-op or clear error

Suggested fix

Check the backing field (this._component._mode via an internal accessor / a hasMode getter) so the early return works as intended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions