gpu.js“错误:内核参数不足”

问题描述

我正在制作的 React 应用程序中有一些计算量很大的画布效果。我一直试图弄清楚如何去做大约 2 天,它几乎可以工作,但我有一个我似乎无法弄清楚的错误

这是运行其中一种效果计算的代码

drawBubbles = () => {
  const ctx = this.Canvas.getContext("2d");

  ctx.strokeStyle = "white";
  ctx.globalAlpha = 0.6;

  if (this.bubbles.length) {
    const gpu = new GPU();
    const kernel = gpu
      .createKernel(function ([
        bubbles,canvasWidth,canvasHeight,beginPath,arc,stroke,]) {
        const bubble = bubbles[this.thread.x];

        bubble[1] -= bubble[2];
        if (bubble[1] + bubble[2] * 2 < 0) {
          bubble[1] = canvasHeight + bubble[2] * 2;
          bubble[0] = Math.random() * canvasWidth;
        }

        if (Math.floor(Math.random() * 2) === 0) {
          bubble[0] += Math.random() * 6 - 2.5;
        }

        ctx.linewidth = bubble[2] / 2.5;

        beginPath();
        arc(bubble[0],bubble[1],bubble[2] * 2,2 * Math.PI);
        stroke();

        return bubble;
      })
      .setoutput([this.bubbles.length]);

    this.bubbles = kernel([
      this.bubbles,this.Canvas.width,this.Canvas.height,ctx.beginPath,ctx.arc,ctx.stroke,]);
  } else {
    for (let i = 0; i < 15; i++) {
      this.bubbles.push([
        // 0 = X
        Math.random() * this.Canvas.width,// 1 = Y
        Math.random() * this.Canvas.height,// 2 = Size/Speed
        Math.random() * 3 + 1,]);
    }
  }
};

Error output

当我查看它时我一无所知,如果我不实现它,那么我的应用程序将以 10-20 fps(或在较慢的计算机上更低)运行

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)