Reskillable

Reskillable

12M Downloads

Button render can cause null pointer crash

Charnuz opened this issue ยท 2 comments

commented

This for some reason happened as I went to exit world.

Reskillable: 1.12.5
Forge: 14.23.5.2838

crash.txt

commented

Not sure why this was happening but added something that should fix it. I hope to release an update by the end of the week that includes this fix.

commented

Can confirm this still happens with version 1.13.0. Created a new issue #181 as the button itself is not the cause.

public class PlayerDataHandler {
private static final String DATA_TAG = "SkillableData";
private static HashMap<Integer, PlayerData> playerData = new HashMap<>();
public static PlayerData get(EntityPlayer player) {
if (player == null) {
return null;
}
int key = getKey(player);
if (!playerData.containsKey(key)) {
playerData.put(key, new PlayerData(player));
}
PlayerData data = playerData.get(key);
if (data.playerWR.get() != player) {
NBTTagCompound cmp = new NBTTagCompound();
data.saveToNBT(cmp);
RequirementCache.removeCache(player.getUniqueID(), player.getEntityWorld().isRemote);
playerData.remove(key);
data = get(player);
data.loadFromNBT(cmp);
}
return data;
}

Depending on if PlayerDataHandler.get() can return null (meaning PlayerData.get() also can return null), the button should handle this properly.

The button itself appears to handle null correctly.

public enum TabType {
INVENTORY(1, null),
SKILLS(0, null),
ABILITIES(2, PlayerData::hasAnyAbilities);
public final int iconIndex;
private Predicate<PlayerData> renderPred;
TabType(int iconIndex, Predicate<PlayerData> render) {
this.iconIndex = iconIndex;
this.renderPred = render;
if (renderPred == null) {
renderPred = data -> true;
}
}
public boolean shouldRender() {
PlayerData data = PlayerDataHandler.get(Minecraft.getMinecraft().player);
return data != null && renderPred.test(data);
}
}