I'm trying to port the RGSS3 script I made (a script that changes the color of the HP bar depending on the remaining HP). I have wrote most of the logic, but for some reason when it reaches to the point of the low hp (and only that point), the game crashes with error "TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': float parameter 1 is non-finite." Any character who's ouf of the limit shows the correct color.
Here's the code:
And here's the error log:
TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': float parameter 1 is non-finite.
at TypeError (native)
at Bitmap.getPixel (<game's folder>/js/rpg_core.js:906:30)
at Window_MenuStatus.Window_Base.textColor (<game's folder>/js/rpg_windows.js:176:28)
at Window_MenuStatus.Window_Base.hpColor (<game's folder>/js/plugins/HPColor.js:144:18)
at Window_MenuStatus.Window_Base.drawActorName (<game's folder>/js/rpg_windows.js:500:31)
at Window_MenuStatus.drawItem (<game's folder>/js/rpg_windows.js:1736:10)
at Window_MenuStatus.Window_Selectable.drawAllItems (<game's folder>/js/rpg_windows.js:1250:18)
at Window_MenuStatus.Window_Selectable.refresh (<game's folder>/js/rpg_windows.js:1277:14)
Here's the code:
Code:
Window_Base.prototype.hpTextColorPicker = function(actor) {
if (actor.hp < actor.mhp * CriticalHPLimit) return this.textColor(CriticalHPText);
else if (actor.hp > actor.mhp * CriticalHPLimit && actor.hp < actor.mhp * LowHPLimit) return this.textColor(HPLowText);
else return this.systemColor();
};
Window_Base.prototype.hpbarColorPicker1 = function(actor) {
if (actor.hp < actor.mhp * CriticalHPLimit) return this.textColor(CriticalHPBar1);
else if (actor.hp > actor.mhp * CriticalHPLimit && actor.hp < actor.mhp * LowHPLimit) return this.textColor(HPBarLow1);
else if (CompatMode == true) this.hpGaugeColor1();
else return this.textColor(HPNormalBar1);
};
Window_Base.prototype.hpbarColorPicker2 = function(actor) {
if (actor.hp < actor.mhp * CriticalHPLimit) return this.textColor(CriticalHPBar2);
else if (actor.hp > actor.mhp * CriticalHPLimit && actor.hp < actor.mhp * LowHPLimit) return this.textColor(HPBarLow2);
else if (CompatMode == true) this.hpGaugeColor2();
else return this.textColor(HPNormalBar2);
};
this.Window_Base.prototype.drawActorHp = function(actor, x, y, width) {
width = width || 186;
var color1 = this.hpbarColorPicker1(actor);
var color2 = this.hpbarColorPicker2(actor);
this.drawGauge(x, y, width, actor.hpRate(), color1, color2);
this.changeTextColor(this.hpTextColorPicker(actor));
this.drawText(TextManager.hpA, x, y, 44);
this.drawCurrentAndMax(actor.hp, actor.mhp, x, y, width,
this.hpColor(actor), this.normalColor());
};
Window_Base.prototype.hpColor = function(actor) {
if (actor.isDead()) {
return this.deathColor();
} else if (actor.hp < actor.mhp * CriticalHPLimit)
return this.textColor(CriticalHPText);
else if (actor.hp > actor.mhp * CriticalHPLimit && actor.hp < actor.mhp * LowHPLimit)
return this.textColor(HPLowText);
else {
return this.normalColor();
}
};
TypeError: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': float parameter 1 is non-finite.
at TypeError (native)
at Bitmap.getPixel (<game's folder>/js/rpg_core.js:906:30)
at Window_MenuStatus.Window_Base.textColor (<game's folder>/js/rpg_windows.js:176:28)
at Window_MenuStatus.Window_Base.hpColor (<game's folder>/js/plugins/HPColor.js:144:18)
at Window_MenuStatus.Window_Base.drawActorName (<game's folder>/js/rpg_windows.js:500:31)
at Window_MenuStatus.drawItem (<game's folder>/js/rpg_windows.js:1736:10)
at Window_MenuStatus.Window_Selectable.drawAllItems (<game's folder>/js/rpg_windows.js:1250:18)
at Window_MenuStatus.Window_Selectable.refresh (<game's folder>/js/rpg_windows.js:1277:14)