Warning “WebGL: INVALID_ENUM: activeTexture: texture unit out of range” in console in Game on Pixi.js

1k views Asked by At

I'm writing a game on PIXI.js. The bottom line is that everything works as intended. But at some point in the console pops up a warning "WebGL: INVALID_ENUM: activeTexture: texture unit is out of range" and textures in the game a little flash.

This error appears in a strange time and at the same time lost

There is a class for creating a monster and his method that moves a monster:

function Monster (monsterImages, startX) {
    this.hideEnemy = false;
    var frames = [];

    for (var i = 0; i < monsterImages.length; i++) {
        var texture = Texture.fromImage(monsterImages[i]);
        frames.push(texture);
    }

    this.movieclip = new PIXI.extras.AnimatedSprite(frames);

    this.movieclip.scale.x = -1;
    this.movieclip.anchor.set(0.5);
    this.movieclip.width = 170;
    this.movieclip.height = 140;
    this.movieclip.x = startX;
    this.movieclip.y = getRandomIntValue(Position.START_Y + this.movieclip.height / 2, Position.END_Y + this.movieclip.height / 2);
    this.movieclip.animationSpeed = 0.4;

    this.movieclip.play();
    gameScene.addChild(this.movieclip);
}

Monster.prototype.updatePosition = function () {
    if (this.movieclip.x > Position.END_X - this.movieclip.width / 2) {
        this.movieclip.x -= Position.STEP_X;
    } else {
        // this.hideEnemy = true;

        this.movieclip.x = Position.START_X;
        this.movieclip.y = getRandomIntValue(Position.START_Y + this.movieclip.height / 2, Position.END_Y + this.movieclip.height / 2);
    }
};

I create 4 monsters:

for (var i = 0; i < 4; i++) {
    enemy[i] = new Monster(monsterSprites[i], 1920 + 170 + gapBetweenBirds);
    gapBetweenBirds+=500;
}

Then I move them by method "updatePosition", and if it is out of the scene, then I cut out of an array of this monster, and to insert the new.:

for (var i = 0; i < enemy.length; i++) {
        enemy[i].updatePosition();
        if (enemy[i].hideEnemy) {
            enemy.splice(i, 1, new Monster(monsterSprites[getRandomIntValue(0,monsterSprites.length - 1)], 1920 + 170));
        }
    }

The problem came when I began to replace the monster in the array. I think the problem is out there, but due to the little experience I can not catch her.

1

There are 1 answers

0
D.Nazdratenko On

I decided problem. I need to destroy object which I deleted from array because it is used in rendering.

I add

this.movieclip.destroy();
this.movieclip = null;

in Monster.prototype.updatePosition

So I have

Monster.prototype.updatePosition = function () {
    if (this.movieclip.x > Position.END_X - this.movieclip.width / 2) {
        this.movieclip.x -= Position.STEP_X;
    } else {
        this.hideEnemy = true;
        this.movieclip.destroy();
        this.movieclip = null;
    }
};