Exception when creating a shadow generator: "Cannot read properties of undefined (reading 'textureFloatRender')"

I’m trying to move my oversized plyground scene into my actual codebase and run it locally, however when I try and create a shadow generator (new BABYLON.ShadowGenerator(1024, light, true);) the following is thrown:

babylon.js?633b:16 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘textureFloatRender’)

at new e (babylon.js?633b:16)
at Function.eval (babylon.ts?7878:839)
at Generator.next (<anonymous>)
at eval (babylon.ts:14)
at new Promise (<anonymous>)
at __awaiter (babylon.ts:10)
at Function.CreateScene (babylon.ts?7878:819)
at VueComponent.created (HomeBase.vue?be5d:36)
at invokeWithErrorHandling (vue.runtime.esm.js?2b0e:1854)
at callHook (vue.runtime.esm.js?2b0e:4219)
    "babylonjs": "^4.2.0",
    "babylonjs-gui": "^4.2.0",
    "babylonjs-materials": "^4.2.0",
    "babylonjs-post-process": "^4.2.0",

textureFloatRender is a caps that is read by engine.getCaps().textureFloatRender.

Your error message means that engine.getCaps() is undefined, which is not really possible as the caps are filled in the engine constructor. However, if you don’t pass a canvas to this constructor, there’s an early exit and the caps won’t be filled, so I guess it’s your problem (your are passing a null/undefined canvas).

2 Likes

Yep, that was it. :man_facepalming:

Suggestion: Constructors should throw when invalid params are provided. Objects should guard their state in that regard, and exceptions during construction can be far more helpful than unexpected consequences far removed from construction.

Are you accepting PRs for that kinda stuff?


Man, I would have saved so many hours of debugging if I even had a hint that I was passing an undefined canvas in…

1 Like

Actually, passing a null value for the canvas is allowed:

Constructor of Engine:

constructor(canvasOrContext: Nullable<HTMLCanvasElement | OffscreenCanvas | WebGLRenderingContext | WebGL2RenderingContext>, antialias?: boolean, options?: EngineOptions, adaptToDeviceRatio: boolean = false)

I don’t know why, however. Maybe @sebavan will know.

nullEngine would not require a canvas at init time :slight_smile: