YetAnotherConfigLib

YetAnotherConfigLib

34M Downloads

`ColorPickerWidget` throws an NPE when allowAlpha is false.

Emirlol opened this issue ยท 0 comments

commented

The exception is thrown upon clicking on the color picker button to open the picker. In ColorPickerWidget#render:

//? if >=1.21.9 {
if (isHoveringHueSlider(mouseX, mouseY)) {
graphics.requestCursor(com.mojang.blaze3d.platform.cursor.CursorTypes.RESIZE_EW);
} else if (isHoveringAlphaSlider(mouseX, mouseY)) {
graphics.requestCursor(com.mojang.blaze3d.platform.cursor.CursorTypes.RESIZE_EW);

The picker opens towards the bottom so the hue slider check is false,
Image
so the else if branch for the alpha slider is entered next, which checks for the dimensions of the alphaGradientDim field:
private boolean isHoveringAlphaSlider(double mouseX, double mouseY) {
return mouseY >= alphaGradientDim.y() && mouseY <= alphaGradientDim.yLimit()
&& mouseX >= alphaGradientDim.x() && mouseX <= alphaGradientDim.xLimit();
}

But this field is only initialized from ColorPickerWidget#setDimension, and is otherwise null:

hueGradientDim = Dimension.ofInt(colorPickerDim.x(), colorPickerDim.yLimit() - sliderHeight - alphaSliderHeight, colorPickerDim.width(), sliderHeight);
if (controller.allowAlpha()) {
alphaGradientDim = Dimension.ofInt(hueGradientDim.x(), hueGradientDim.y() + alphaSliderHeight, hueGradientDim.width(), sliderHeight);
}

Hence, a NPE is thrown.