question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot assign to read only property 'RGBA16F' of object in strict mode

See original GitHub issue

Edit: This is caused by strict mode, see https://github.com/BabylonJS/Babylon.js/issues/2988#issuecomment-340539936

I have the exact same error as https://github.com/BabylonJS/Babylon.js/issues/2642 but the issue is closed and I don’t know why and how it has been resolved by OP

Context:

  • Developing on localhost
  • With MacOSX and ArchLinux
  • With Chrome and Firefox
  • Using babylonjs as a CommonJS module with rollup (and babel)
  • With babylon.3.0-beta12.max.js and babylon.3.0-beta12.js (with and without npm)

Error:

babylon.3.0-beta12.max.js:7623 Uncaught TypeError:
Cannot assign to read only property 'RGBA16F' of object '#<WebGL2RenderingContext>'
   at new Engine (babylon.3.0-beta12.max.js:7623)

It looks like the following WebGL constants RGBA16F, RGBA32F and DEPTH24_STENCIL8 are read only and cannot be set during engine creation.

See: https://github.com/BabylonJS/Babylon.js/blob/7482c84713f0b97d32e3e1a1ac42b70893b77468/src/Engine/babylon.engine.ts#L1080-L1083

Strangely HALF_FLOAT_OES can be set without any problem…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

7reactions
yvelecommented, Oct 30, 2017

@deltakosh I still have the issue with the latest release

I’ve seen that you’ve reverted the if (...) thing here in this commit 🤔 Why did you revert this? Is it related to strict check null #2982?

I figured out exactly why this is happening using a bundler like rollup or webpack, the thing is that the bundler is enabling strict mode by default by adding 'use strict'; which is good for ES6

In rollup documentation https://rollupjs.org/#strict

Strictly-speaking, ES6 modules are always in strict mode, so you shouldn’t disable this without good reason.

So I still have the problem with those 3 lines:

this._gl.RGBA16F = 0x881A; // RGBA 16-bit floating-point color-renderable internal sized forma
this._gl.RGBA32F = 0x8814; // RGBA 32-bit floating-point color-renderable internal sized forma
this._gl.DEPTH24_STENCIL8 = 35056;

But also in new Mesh(...) at this line, the Tools.DeepCopyfunction is throwing at this line:

Uncaught TypeError: Cannot set property source of [object Object] which has only a getter
    at Function.Tools.DeepCopy (babylon.3.0.7.max.js:5704)
    at new Mesh (babylon.3.0.7.max.js:19816)
    at Mesh.clone (babylon.3.0.7.max.js:21060)

The error details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Getter_only

There is an attempt to set a new value to a property for which only a getter is specified. While this will be silently ignored in non-strict mode, it will throw a TypeError in strict mode.

Seems like Mesh.source is a getter (from this._source) and then cannot be set ⚠️

My workaround is to disable strict mode in my bundler, but I think there is several benefits to use strict mode directly in BabylonJS in development mode. In production mode we should be able to use it or not because there are many resources about performance improvements, see this and this and this.

@deltakosh do you want me to create 2 separate issues? Or to create another issue called Enable strict mode? Do you also think enabling strict mode is a good thing?

@vousk CC

3reactions
deltakoshcommented, Oct 30, 2017

I’m in a middle of an update so I’ll add it no worry 😃 (directly though)

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot assign to read-only property of object - Stack Overflow
the first approach you are mutating action.payload directly since you are not creating a copy to newItem but passing the same reference.
Read more >
Cannot assign to read only property of Object in JavaScript
The error "Cannot assign to read only property of object" occurs when we try to change a property of an object that has...
Read more >
PBR shader error on WebGL1.0 - Bugs - Babylon.js Forum
I can not seem to reproduce with other models ? ... Cannot assign to read only property 'RGBA16F' of object in strict mode....
Read more >
JavaScript Cannot Assign to Read-only Property of Object in ...
Try and test HTML code online in a simple and easy way using our free HTML editor and see the results in real-time....
Read more >
TypeError: "x" is read-only - JavaScript - MDN Web Docs
The JavaScript strict mode-only exception "is read-only" occurs when a global variable or object property that was assigned to is a read-only property....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found