-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new Model(shapes, undefined) throws a TypeError #310
Comments
In fact if you look through BUT, that being said--if I were to write the same function in JavaScript, I would almost certainly check for |
@postcasio Workaround for your specific case: const shader = FS.exists(shaderPath) ? loadShader(shaderPath) : Shader.Default;
return new Model(shapes, shader); |
You could compare against undefined AND null? |
No, because it's not valid to set no shader for a model, so The current implementation does the equivalent of this: if (arguments.length >= 2) {
if (!(arguments[1] instanceof Shader))
throw TypeError("not a shader");
this.shader = arguments[1];
}
else {
this.shader = Shader.Default;
} which fails for @postcasio's use case above. Normally I consider such failure to be desirable: when an In this case though, were I writing a function, I do normally check for |
Ah right - I see I thought you were implying that you only didn't check for undefined as checking for both null and undefined would be weird. I see your point though - if someone passes undefined - is it because they didn't mean to pass an argument at all OR is it because they forgot to initialise something. Hmm I wonder what the JS library methods do for that, will have to check/I wonder if it's consistent. |
the constructor for
Model
accepts an optional second argument,shader
, to specify the shader. If you explicitly passundefined
for this argument, it throwsTypeError: 'undefined' is not a Shader object
. The C method only checks the number of arguments passed to determine if a shader was supplied, but it should also check if the argument is undefined.This breaks simple code like:
The text was updated successfully, but these errors were encountered: