Skip to content

RayTracer.dispose() throws when a solver is deleted before it has run #89

Description

@rdmiller

Deleting a Ray Tracer that has never been run throws, and the delete does not complete.

Reproduce

  1. Open the CRAM editor
  2. Solvers → Raytracer (adds a solver)
  3. Click the trash icon next to it without pressing Run

Error

TypeError: Cannot convert undefined or null to object
    at Object.keys (<anonymous>)
    at RayTracer.dispose (compute/raytracer/index.ts:435)
    at emit
    at onDelete

Cause

RayTracer.dispose() does:

// src/compute/raytracer/index.ts:435
Object.keys(window.vars).forEach(key => {
  if (window.vars[key]['uuid'] === this.uuid) {
    delete window.vars[key];
  }
})

window.vars is only created lazily by registerGlobalVar (src/common/global-vars.ts:7), which a Ray Tracer reaches during a run. Delete a solver that never ran and window.vars is still undefined, so Object.keys(undefined) throws.

Because the throw happens partway through dispose(), the two lines after it never execute either:

renderer.scene.remove(this.rays);
renderer.scene.remove(this.hits);

so the solver's ray and hit objects are left attached to the scene.

Suggested fix

Guard the lookup (window.vars ?? {}), or initialise window.vars once at module load in common/global-vars.ts so every consumer can assume it exists.

Notes

Pre-existing and unrelated to any current PR — found incidentally while testing #87. Reachable with no geometry involved: adding a solver and immediately deleting it is enough.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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