r/webgl • • 1h ago

Error when not directly calling gl function

This code works:

(gl.uniformMatrix3fv)(
    uMatrix, true,
    [
    	1, 0, 0,
    	0, 1, 0,
    	0, 0, 1
    ])

But this code gives the error "Uncaught TypeError: 'uniformMatrix3fv' called on an object that does not implement interface WebGL2RenderingContext"

(true && gl.uniformMatrix3fv)(
    uMatrix, true,
    [
    	1, 0, 0,
    	0, 1, 0,
    	0, 0, 1
    ])

I have never seen javascript act like this. Is there some kind of typing or macro I don't know about?

1 Upvotes

1 comment sorted by

1

u/Minute-Project-7200 10m ago

When you do (true && gl.uniformMatrix3fv), it evaluates to true, so you are really doing 

(true)(
    uMatrix, true,
    [
     1, 0, 0,
     0, 1, 0,
     0, 0, 1
    ])

It is calling true of which is not a function. I dont know how you got that specific type error though. It should be saying something different. The first one is valid as

(gl.uniformMatrix3fv)(
    uMatrix, true,
    [
     1, 0, 0,
     0, 1, 0,
     0, 0, 1
    ])

is equivalent to calling the function directly.

gl.uniformMatrix3fv(
    uMatrix, true,
    [
     1, 0, 0,
     0, 1, 0,
     0, 0, 1
    ])