使用cc.RenderTexture.create,导出微信小游戏的工程后会报gl.texImage2D的错误

我使用cc.RenderTexture.create创建RT,在模拟器和浏览器下都能正常工作。导出微信小游戏的工程后会报以下错误

Failed to execute 'texImage2D' on 'WebGLRenderingContext': No function was found that matched the signature provided.
TypeError: Failed to execute 'texImage2D' on 'WebGLRenderingContext': No function was found that matched the signature provided.
    at CCClass.216.game.once._p._setImage (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:38169:189)
    at CCClass.216.game.once._p.update (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:38152:22)
    at CCClass.216.game.once._p.initWithData (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:38191:18)
    at 269.cc.RenderTexture.WebGLRenderCmd.269.proto.initWithWidthAndHeight (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:46449:18)
    at TheClass.initWithWidthAndHeight (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:46208:32)
    at TheClass.ctor (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:46175:16)
    at new TheClass (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:32903:16)
    at Function.267.cc.RenderTexture.create (http://127.0.0.1:54271/game/cocos2d-js.071b3.js:46289:14)

看了一下代码,是gl.texImage2D调用时候出错

         if ( sys.platform === sys.WECHAT_GAME ||
                sys.platform === sys.QQ_PLAY ||
                img instanceof HTMLCanvasElement ||
                img instanceof HTMLImageElement ||
                img instanceof HTMLVideoElement
            ) {
                gl.texImage2D(
                    gl.TEXTURE_2D,
                    0,
                    glFmt.internalFormat,
                    glFmt.format,
                    glFmt.pixelType,
                    img
                );
            }

有哪位大侠知道怎么解决这个问题吗?

1赞

同问, 我也发现这问题, 难道是微信小程序不支持

gl.texImage2D(
   gl.TEXTURE_2D,
   0,
   glFmt.internalFormat,
   glFmt.format, 
   glFmt.pixelType,
   img
);

同问 顶你不要沉

使用cc.RenderTexture.create,导出微信小游戏的工程后会报gl.texImage2D的错误 继续讨论:
使用自定义引擎,然后在修改下引擎源码文件的这个位置的代码
主要是加了 ((img instanceof Uint8Array) == false) ,微信这边有个BUG。

2赞

感谢!

相应修改后 不会报错 但发现另外一个问题

var renderTexture = cc.RenderTexture.create(Math.floor(width), Math.floor(height));
renderTexture.begin();
node._sgNode.visit(); // 精灵 或者 Graphics
renderTexture.end();

在浏览器和构建后微信开发工具中 都正常
但如果在微信开发工具中通过二维码在手机微信上调试 则发现通过renderTexture截取的图像被一定比例放大了

如 我绘制一个圆形(50r)在RT(50x50)中 浏览器中能显示完整圆形 但 到了微信上则只剩下圆形左上角部分


可以给个demo看看。

在微信开发工具里和扫二维码在手机上看 就可以看出区别了assets.zip (46.8 KB)

使用iphone se测试和开发者工具效果是一样的。

确实iphone没问题 问题出现在安卓手机这边 麻烦尝试下~

同遇到这个问题 而且用new cc.SpriteFrame(this.rt.sprite._texture)生成的图片是倒着的

请问这个问题现在解决了吗?

请问 是否有在安卓机排查到这个情况呢~?

我跟踪一下,看看问题是什么~

我直接在原引擎上面改不行么,为啥我按照4楼改还是会报错

使用自定义引擎的时候报错了,编译不了微信小游戏是为什么呢?
报错信息:

Failed to load url scene://utils/animation, please register the protocol for it.
Finish building assets
Build Failed: Error: AssertionError: missing path
AssertionError: missing path
Failed to load url scene://utils/animation, please register the protocol for it.
Exception TypeError: Cannot read property ‘nativeWin’ of null

小游戏没有saveToFile 方法啊。怎么破大神们?
错误信息:saveToFile isn’t supported on Cocos2d-Html5

我也遇上了这个问题,现在有解决吗

大大,我想问一下安卓微信上截取图像被一定比例放大这个问题有解决方案吗

请问,现在这个问题有解决方案了吗