Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

A float parameter 1 isn't finite?

AceOfAces

Villager
Xy$
0.11
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:
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();
    }
};
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)
 

Xilefian

Adventurer
Xy$
0.00
Can you tell us the values you've set to these variables;
  • CriticalHPLimit
  • CriticalHPText
  • LowHPLimit
  • HPLowText
  • HPBarLow1
  • CompatMode
  • HPNormalBar1
  • CriticalHPBar2
  • HPBarLow2
  • HPNormalBar2
The error indicates that you're passing an invalid value to textColor, which expects an integer from 0 to 31. It may be the case that you forgot to assign one of these variables that you have not included in your pasted code.

So one of your this.textColor calls is using a non-numeric value at some point.
 

AceOfAces

Villager
Xy$
0.11
@Xilefian ,

CriticalHPLimit float, set to 0.15
CriticalHPText interger, set to 18
LowHPLimit float, set to 0.25
HPLowText interger, set to 2
HPBarLow1 interger, set to 20
CompatMode Boolean, set to false
HPNormalBar1 Interger set to 11
CriticalHPBar2 Interger, set to 2
HPBarLow2 Interger, set to 22
HPNormalBar2 Interger, set to 3

And this is how the variables are loaded:

// Reference the Plugin Manager's parameters.
var paramdeck = PluginManager.parameters('HPColor');
//Load variables set in the Plugin Manager.
var CompatMode = String(paramdeck['Compatibility Mode']).trim().toLowerCase() === 'true';
var LowHPLimit = parseFloat(paramdeck['Low HP']);
var CriticalHPLimit = parseFloat(paramdeck['Critical HP']);
var HPNormalBar1 = Number(paramdeck['Normal HP Color 1']);
var HPNormalBar2 = Number(paramdeck['Normal HP Color 2']);
var HPLowText = Number(paramdeck['Low HP Text']);
var HPBarLow1 = Number(paramdeck['Low HP Bar Color 1']);
var HPBarLow2 = Number (paramdeck['Low HP Bar Color 2']);
var CriticalHPText = Number(paramdeck['Critical HP Text']);
var CriticalHPBar1 = Number(paramdeck['Critical HP Bar Color 1']);
var CriticalHPBar2 = Number(paramdeck['Critical HP Bar Color 2']);
 

Xilefian

Adventurer
Xy$
0.00
I think you should set a breakpoint and inspect the value being passed to textColor, see which one of these variables is causing the problem.

It's almost certainly a problem with the textColor argument, according to your error message.

It's either CriticalHPText or HPLowText that is not a valid number. The error indicates that you haven't pasted all your code so I can't pin-point the exact problem.

Also for the sake of type safety, consider using parseInt rather than Number to parse your integers; Number can return a float type and your error message is complaining about a float input, so that could be the problem (which would suggest you may have set up your parameters incorrectly).
 
Last edited:

AceOfAces

Villager
Xy$
0.11
Something that I noticed is that when it tried to get the hp text color (via the hpcolor) it jumped to the second party member.

I've attached the plugin, if it helps debugging it better...
 

Attachments

Xilefian

Adventurer
Xy$
0.00
Saw the problem straight away;

The parameter "Low HP Text" doesn't exist, you've called it "Low HP Text Color" (line 29) in the params list, but are dereferencing it as "Low HP Text" (line 98).

This is why it's important to paste as much code as possible, you'll see that the first thing I asked about what the initialisation of the variables that weren't included in your original snippet, the params section is part of that initialisation so that's where I looked first when I downloaded your attached Plugin.
 
Last edited:

changed

Villager
Xy$
0.00
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:
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();
    }
};
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)
It's hard to understand @@


_________________________
123MOVIES
 
Top