- 当前 Bug 的表现(图1)
- 预期表现(图2)
在点击复选框时,比如点击图示背景音乐,想渲染大图里某一部分(复选框变成选中状态),但是在客户端里整个背景都变成了一片黑,并且反复渲染了很多复选框,甚至把vConsole也渲染进去了(调试状态下),见图1,在开发者工具里正常,见图2。此BUG必现,代码示例:
import ImageLoader from ‘./imageLoader’
const { screenWidth, screenHeight, devicePixelRatio } = wx.getSystemInfoSync()
const canvas = wx.createCanvas()
const ctx = canvas.getContext(‘2d’)
const img = wx.createImage();
img.src = ‘images/all.png’;
export default class Main
{
constructor(){
let imgLoader = new ImageLoader();
imgLoader.loadFile([‘images/bg.jpg’,‘images/all.png’], ()=>{
let back=wx.createImage();
back.src=‘images/bg.jpg’;
//背景
ctx.drawImage(back,0,0,back.width,back.height,0,0,screenWidth,screenHeight);
//复选框
ctx.drawImage(img,459,287,13,13,100,100,13,13);
wx.onTouchStart((e)=>{
//选中复选框
ctx.drawImage(img,614,287,13,13,100,100,13,13);
});
})
}
}
export default class ImageLoader
{
load(){
if(this.queue.length){
let img = wx.createImage();
img.onload = ()=>{
this.load()
}
img.src = this.queue.shift();
}else{
this.callback()
}
}
loadFile(_arrs, _callback){
this.queue = _arrs;
this.callback = _callback;
this.load()
}
}
补充:
之前已经有人也发现了同样的BUG。