Deleting a Ray Tracer that has never been run throws, and the delete does not complete.
Reproduce
- Open the CRAM editor
- Solvers → Raytracer (adds a solver)
- 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.
Deleting a Ray Tracer that has never been run throws, and the delete does not complete.
Reproduce
Error
Cause
RayTracer.dispose()does:window.varsis only created lazily byregisterGlobalVar(src/common/global-vars.ts:7), which a Ray Tracer reaches during a run. Delete a solver that never ran andwindow.varsis stillundefined, soObject.keys(undefined)throws.Because the throw happens partway through
dispose(), the two lines after it never execute either:so the solver's ray and hit objects are left attached to the scene.
Suggested fix
Guard the lookup (
window.vars ?? {}), or initialisewindow.varsonce at module load incommon/global-vars.tsso 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.