WebGL Error: Not all control paths return a value
WebGL Error: Not all control paths return a value
我的一些客户无法初始化 webGL 程序。我正在使用
捕获错误
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error("Unable to initialize the shader program: " + gl.getProgramInfoLog(program));
}
我得到的日志是
Unable to initialize the shader program:
C:\fakepath(72,30-133): error X3507: '_directionToColor':
Not all control paths return a value
我无法在我的计算机上重现此错误。有谁知道出了什么问题?如果有帮助,我很乐意分享更多代码:)
Not all control paths return a value
是一个错误,如果您的函数看起来像
,编译器将抛出该错误
if (...) {
return ...
} else if (...) {
return ...
}
即使始终满足两个条件之一,编译器也不够聪明,无法识别并抛出错误。因此,您必须将 else if
更改为 else
或添加第三个 return 语句,该语句实际上永远不会被使用。
我发现在某些环境中着色器可以正常编译,而在其他环境中 (windows) 它会失败。
我在我的代码中找不到 _directionToColor
,因为函数名称是 directionToColor
并且以某种方式添加了下划线。
我的一些客户无法初始化 webGL 程序。我正在使用
捕获错误gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
throw new Error("Unable to initialize the shader program: " + gl.getProgramInfoLog(program));
}
我得到的日志是
Unable to initialize the shader program:
C:\fakepath(72,30-133): error X3507: '_directionToColor':
Not all control paths return a value
我无法在我的计算机上重现此错误。有谁知道出了什么问题?如果有帮助,我很乐意分享更多代码:)
Not all control paths return a value
是一个错误,如果您的函数看起来像
if (...) {
return ...
} else if (...) {
return ...
}
即使始终满足两个条件之一,编译器也不够聪明,无法识别并抛出错误。因此,您必须将 else if
更改为 else
或添加第三个 return 语句,该语句实际上永远不会被使用。
我发现在某些环境中着色器可以正常编译,而在其他环境中 (windows) 它会失败。
我在我的代码中找不到 _directionToColor
,因为函数名称是 directionToColor
并且以某种方式添加了下划线。