同源图像texImage2D的SecurityError [英] SecurityError for same-origin image texImage2D
问题描述
我目前正在学习WebGL.在对texImage2D的调用中,当纹理完成加载时调用该调用,我得到以下 SecurityError
:
I am currently learning WebGL. In a call to texImage2D, which is called when a texture has finished loading, I get the following SecurityError
:
Uncaught SecurityError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': The cross-origin image at /path/to/texure.png may not be loaded.
但是,该文件与请求该文件的html文件位于同一域中.
However, the file is on the same domain, in fact it is in the same directory as the html file requesting it.
这是文件布局:
> js
|-> script.js
|-> glUtils.js
|-> sylvester.js
> texture.png
> index.html
当我在F12控制台的资源列表中查看时,图像 texture.png
在那里,完全加载,它的大小为256 x256.为什么认为我正在向另一个域请求?
And when I look in the F12 console's resource list, the image texture.png
is there, fully loaded, and it is 256 x 256. Why does it think I am requesting from another domain?
推荐答案
解决方案是您必须位于本地Web服务器上,因为不会授予file:///域请求.(Pointy提供的信息:
The solution is that you must be on a local webserver, because file:/// domain requests will not be granted. (Information given by Pointy:
如果您从本地网络服务器提供内容,则它将起作用,因为浏览器将看到它们来自同一域.Chrome曾经有一个命令行选项允许它:--allow-file-access-from-files,但我不知道它是否仍然可以工作
If you serve up the stuff from a local webserver it'll work, because the browser will see those as being from the same domain. Chrome used to have an command-line option to allow it: --allow-file-access-from-files but I don't know if it still works
这篇关于同源图像texImage2D的SecurityError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!