Skip to content

ColorPickerWidget throws an NPE when allowAlpha is false. #296

@Emirlol

Description

@Emirlol

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions