Button (and possibly other elements) BIG problem!

Just spent the last several hours trying to find why a stupid button wasn’t changing state (enabled/disabled).

The UID is the same, but logging reported differences.

At creation the button has proper value of disabled after being disabled. (Yay!)

But, when trying to turn it enabled after a certain condition has been met, the lib tells me it’s already enabled. (Wait what!?)

It figures, the hashcode is DIFFERENT even though the UID is the same.

So, there’s something BAD happening in the background. I guess the original button is copied and not all its properties are or there’s something more sinister going on. No need to say this is unacceptable. Any created element using a specific name should be retrievable with its full set of values intact.

Here’s a quick rundown of the code:

[java]
ButtonAdapter loadGameBtn = new ButtonAdapter(screen, “LoadGameButton”, new Vector2f(x, y)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
evt.setConsumed();
manager.playClickOn();
String selectionName = ((SavedGameInfo) ((SelectList) screen.getElementById(“SavedWorldsList”)).getSelectedListItems().get(0).getValue()).getGameName();
loadGame(selectionName);
}
};
loadGameBtn.setText(“Load”);

    // [ irrelevant code ]
    saveGamesInfoPanel.addChild(loadGameBtn);
    saveGamesInfoPanel.addChild(cancelLoadGameBtn);
    saveGamesInfoPanel.setIsVisible(false);

    loadGameBtn.setIsEnabled(false);
    System.out.println("Loading button has been " + (loadGameBtn.getIsEnabled() == true ? "enabled" : "disabled"));

[/java]

This is where the button is enabled:
[java]
SelectList savedWorlds = new SelectList(screen, “SavedWorldsList”, new Vector2f(10f, 10f), new Vector2f(350f, 452f), new Vector4f(10f, 10f, 10f, 10f), “Interface/GUI/Window/panel_x.png”) {
@Override
public void onChange() {
// update info
SavedGameInfo selection = (SavedGameInfo) this.getSelectedListItems().get(0).getValue();
ArrayList<String> formattedText = selection.getFormattedGameInfo();
((SelectList) screen.getElementById(“WorldInfos”)).removeAllListItems();
for (String line : formattedText) {
((SelectList) screen.getElementById(“WorldInfos”)).addListItem(line, null);
}
String imgPath = Utils.getSavePath() + selection.getGameName() + Utils.getFileSeparator() + “screenie.png”;
// screenie.setColorMap(imgPath);
((ButtonAdapter) screen.getElementById(“LoadGameButton”)).setIsEnabled(true);
System.out.println(“Loading button [” + ((ButtonAdapter) screen.getElementById(“LoadGameButton”)).hashCode() + "] has been " + (((ButtonAdapter) screen.getElementById(“LoadGameButton”)).getIsEnabled() == true ? “enabled” : “disabled”));
// System.out.println("Loading button is enabled? " + ((ButtonAdapter) screen.getElementById(“LoadGameButton”)).getIsEnabled());
}
}
[/java]

I also put a debut line in Button.java. Looks like this:

[java]
public void setIsEnabled(boolean isEnabled) {
System.out.println(“Button [” + this.hashCode() + "] is: " +
(this.isEnabled == true ? “enabled” : “disabled”) + ". Setting to: " + (isEnabled == true ? “enabled” : “disabled”));
this.isEnabled = isEnabled;
if (!isEnabled) {
runPressedEffect(false);
} else {
runLoseFocusEffect();
}
}
[/java]

Here’s the output:

Button [589322281] is: enabled. Setting to: disabled Loading button has been disabled Button [1085964614] is: enabled. Setting to: enabled Loading button [1085964614] has been enabled

Turns out, it’s a duplicate name.

Question is, why wasn’t there any warning or, better yet, an exception thrown?

From what I could test out, it seems the second button using the same name was simply dropped… At least I couldn’t find it using the same name.

This needs to be fixed one way or another. Just allowing that to happen is wrong.

@madjack said: Turns out, it's a duplicate name.

Question is, why wasn’t there any warning or, better yet, an exception thrown?

From what I could test out, it seems the second button using the same name was simply dropped… At least I couldn’t find it using the same name.

This needs to be fixed one way or another. Just allowing that to happen is wrong.

When you say duplicate name, do you mean uid? Doesn’t this already throw an error?

I’m trying hard to juggle the memory, but it’s been over a month since I’ve posted this. As I mentioned, there is no error, no warning. The name is accepted even though it was a duplicate, so you can guess, referring to the element using its name gave confusing result.

I’ve just came back from vacations, I’ll take a close look at that part of the code and hopefully that can trigger exactly how I made that happen. But don’t hold your breath.

Was finally able to repro this. Not exactly sure how I did, though… Still, I should be able to narrow down how this bypasses the duplicate id exception… hopefully.

1 Like