Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom UiTheme results in NullPointerException #204

Closed
3 of 7 tasks
lukasknutti opened this issue Aug 13, 2019 · 6 comments
Closed
3 of 7 tasks

Custom UiTheme results in NullPointerException #204

lukasknutti opened this issue Aug 13, 2019 · 6 comments

Comments

@lukasknutti
Copy link

Issue details

When trying to load your custom UiTheme using the AssetManager java exits with a NullPointerException. What i did (simplified):

  • I created a atlas full of different buttons using the Tool (GDX-Texturepacker) this resulted in a buttons.atlas file in my assets directory.
  • As i need to load a JSON full of styling information in my application i've created a buttons.json -> where i specified the different types of buttons and there respective styling -> here's a example with the button -> default "class":
      "rules": {
        "XS": {
          "normal": "Start",
          "hover": "Start_p",
          "action": "Start_p",
          "disabled": "Start",
          "fontSize": 12,
          "font": "default",
          "textColor": "254,254,254",
          "paddingTop": 0,
          "paddingBottom": 0,
          "paddingLeft": 0,
          "paddingRight": 0,
          "marginTop": 12,
          "marginBottom": 12,
          "marginLeft": 12,
          "marginRight": 12
        }
      }
    },
  • Than in my MainMenu.java file i've created an assetManager and try to load my buttons.json file. -> This contains something like that:
   AssetManager assetManager;

    @Override
    public void initialise(GameContainer gc) {
        FileHandleResolver fileHandleResolver = new FallbackFileHandleResolver(new ClasspathFileHandleResolver(), new InternalFileHandleResolver());
        assetManager = new AssetManager(fileHandleResolver);
        assetManager.setLoader(UiTheme.class, new UiThemeLoader(fileHandleResolver));
        assetManager.load("ui/buttons/buttons.json", UiTheme.class);
        UiContainer.setTheme(assetManager.get("ui/buttons/buttons.json", UiTheme.class));
  • also i've added the assetManager.update() function to my update() function which should load all assets (which it does referring to the console output)

  • When running my program, i get an error message saying:

AL lib: (WW) FreeDevice: (0x12a583000) Deleting 3 Buffer(s)
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NullPointerException
	at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:582)
	at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:383)
	at com.my.identifyer.MainMenu.update(MainMenu.java:96)
	at org.mini2Dx.core.screen.BasicScreenManager.update(BasicScreenManager.java:62)
	at org.mini2Dx.core.game.ScreenBasedGame.update(ScreenBasedGame.java:38)
	at org.mini2Dx.core.game.GameWrapper.update(GameWrapper.java:66)
	at com.badlogic.gdx.backends.lwjgl.DesktopMini2DxGame.executeGame(DesktopMini2DxGame.java:249)
	at com.badlogic.gdx.backends.lwjgl.DesktopMini2DxGame$1.run(DesktopMini2DxGame.java:118)
Caused by: java.lang.NullPointerException
	at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:55)
	at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
	at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:99)
	at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:88)
	at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:507)
	at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:381)
	... 6 more

I've tried to trace this issue back to where it came from but did came closer than to the update function of the AssetManager file.

Version of mini2Dx and/or relevant dependencies

1.9.0

Stacktrace

AL lib: (WW) FreeDevice: (0x12a583000) Deleting 3 Buffer(s)
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NullPointerException
	at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:582)
	at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:383)
	at com.my.identifyer.MainMenu.update(MainMenu.java:96)
	at org.mini2Dx.core.screen.BasicScreenManager.update(BasicScreenManager.java:62)
	at org.mini2Dx.core.game.ScreenBasedGame.update(ScreenBasedGame.java:38)
	at org.mini2Dx.core.game.GameWrapper.update(GameWrapper.java:66)
	at com.badlogic.gdx.backends.lwjgl.DesktopMini2DxGame.executeGame(DesktopMini2DxGame.java:249)
	at com.badlogic.gdx.backends.lwjgl.DesktopMini2DxGame$1.run(DesktopMini2DxGame.java:118)
Caused by: java.lang.NullPointerException
	at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:55)
	at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
	at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:99)
	at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:88)
	at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:507)
	at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:381)
	... 6 more

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS
@tomcashman
Copy link
Contributor

Can you provide the full buttons.json?

@lukasknutti
Copy link
Author

Sure, the full buttons.json contains:

{
  "id": "buttons",
  "atlas": "buttons.atlas",
  "buttons": {
    "default": {
      "rules": {
        "XS": {
          "background": "Start ninepatch:12,12,12,12",
          "hoverBackground": "Start ninepatch:12,12,12,12",
          "actionBackground": "Start ninepatch:12,12,12,12",
          "disabledBackground": "Start ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 12,
          "paddingLeft": 12,
          "paddingRight": 12
        }
      }
    },
    "start": {
      "rules": {
        "XS": {
          "background": "Start ninepatch:12,12,12,12",
          "hoverBackground": "Start ninepatch:12,12,12,12",
          "actionBackground": "Start ninepatch:12,12,12,12",
          "disabledBackground": "Start ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 12,
          "paddingLeft": 12,
          "paddingRight": 12
        }
      }
    },
    "back": {
      "rules": {
        "XS": {
          "background": "back ninepatch:12,12,12,12",
          "hoverBackground": "back ninepatch:12,12,12,12",
          "actionBackground": "back ninepatch:12,12,12,12",
          "disabledBackground": "back ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 12,
          "paddingLeft": 12,
          "paddingRight": 12
        }
      }
    },
    "forward": {
      "rules": {
        "XS": {
          "background": "forward ninepatch:12,12,12,12",
          "hoverBackground": "forward ninepatch:12,12,12,12",
          "actionBackground": "forward ninepatch:12,12,12,12",
          "disabledBackground": "forward ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 12,
          "paddingLeft": 12,
          "paddingRight": 12
        }
      }
    },
    "info": {
      "rules": {
        "XS": {
          "background": "info ninepatch:14,8,12,16",
          "hoverBackground": "info ninepatch:14,8,12,16",
          "actionBackground": "info ninepatch:14,8,12,16",
          "disabledBackground": "info ninepatch:14,8,12,16",
          "paddingTop": 12,
          "paddingBottom": 16,
          "paddingLeft": 14,
          "paddingRight": 8
        }
      }
    }
  },
  "checkboxes": {
    "default": {
      "rules": {
        "XS": {
          "disabledBox": "info ninepatch:12,12,12,12",
          "disabledCheck": "info",
          "enabledBox": "info ninepatch:12,12,12,12",
          "enabledCheck": "info",
          "paddingTop": 4,
          "paddingBottom": 4,
          "paddingLeft": 4,
          "paddingRight": 4
        }
      }
    }
  },
  "columns": {
    "default": {
      "rules": {
        "XS": {
        }
      }
    },
    "frame": {
      "rules": {
        "XS": {
          "background": "info ninepatch:24,24,24,24",
          "paddingTop": 4,
          "paddingBottom": 4,
          "paddingLeft": 4,
          "paddingRight": 4
        }
      }
    },
    "tab-menu": {
      "rules": {
        "XS": {
          "background": "info ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 0,
          "paddingLeft": 12,
          "paddingRight": 12
        }
      }
    },
    "tab-content": {
      "rules": {
        "XS": {
          "background": "info ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 12,
          "paddingLeft": 12,
          "paddingRight": 12
        }
      }
    }
  },
  "containers": {
    "default": {
      "rules": {
        "XS": {
          "background": "info ninepatch:24,24,24,24",
          "paddingTop": 24,
          "paddingBottom": 24,
          "paddingLeft": 24,
          "paddingRight": 24
        }
      }
    },
    "no-background": {
      "rules": {
        "XS": {
          "paddingTop": 24,
          "paddingBottom": 24,
          "paddingLeft": 24,
          "paddingRight": 24,
          "marginTop": 0,
          "marginBottom": 0,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    },
    "no-background-no-padding": {
      "rules": {
        "XS": {
        }
      }
    }
  },
  "fonts": {
    "default": {
      "path": "kenvector_future.ttf",
      "fontSize": 12
    },
    "header": {
      "path": "kenvector_future.ttf",
      "fontSize": 18
    }
  },
  "images": {
    "default": {
      "rules": {
        "XS": {
          "paddingTop": 0,
          "paddingBottom": 0,
          "paddingLeft": 0,
          "paddingRight": 0,
          "marginTop": 0,
          "marginBottom": 0,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    }
  },
  "labels": {
    "default": {
      "rules": {
        "XS": {
          "font": "default",
          "textColor": "1,1,1",
          "marginTop": 4,
          "marginBottom": 4,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    },
    "header": {
      "rules": {
        "XS": {
          "font": "header",
          "textColor": "1,1,1",
          "marginTop": 4,
          "marginBottom": 4,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    },
    "tab-button-label": {
      "rules": {
        "XS": {
          "font": "default",
          "textColor": "1,1,1",
          "paddingTop": 0,
          "paddingBottom": 0,
          "paddingLeft": 0,
          "paddingRight": 0,
          "marginTop": 0,
          "marginBottom": 0,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    }
  },
  "progressBars": {
    "default": {
      "rules": {
        "XS": {
          "minHeight": 20,
          "background": "info ninepatch:12,12,12,12",
          "fill": "info ninepatch:8,8,8,8",
          "paddingTop": 2,
          "paddingBottom": 2,
          "paddingLeft": 2,
          "paddingRight": 2
        }
      }
    }
  },
  "radioButtons": {
    "default": {
      "rules": {
        "XS": {
          "font": "default",
          "textColor": "1,1,1",
          "optionsSpacing": 2,
          "labelIndent": 4,
          "active": "info",
          "inactive": "info",
          "disabledActive": "info",
          "disabledInactive": "info"
        }
      }
    }
  },
  "scrollBoxes": {
    "default": {
      "rules": {
        "XS": {
          "minHeight": 32,
          "topScrollButtonStyle": "default",
          "bottomScrollButtonStyle": "default",
          "scrollButtonHeight": "16",
          "scrollBarWidth": "16",
          "scrollTrack": "info ninepatch:4,4,5,5",
          "scrollThumbNormal": "info ninepatch:12,12,12,12",
          "scrollThumbHover": "info ninepatch:12,12,12,12",
          "scrollThumbAction": "info ninepatch:12,12,12,12"
        }
      }
    }
  },
  "selects": {
    "default": {
      "rules": {
        "XS": {
          "buttonWidth": 38,
          "minHeight": 40,
          "enabledLabelStyle": "default",
          "disabledLabelStyle": "default",
          "leftButtonStyle": "info",
          "rightButtonStyle": "info",
          "leftButtonLabelStyle": "default",
          "rightButtonLabelStyle": "default",
          "marginTop": 4,
          "marginBottom": 4,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    }
  },
  "sliders": {
    "default": {
      "rules": {
        "XS": {
          "normal": "info",
          "active": "info",
          "hover": "info",
          "disabled": "info",
          "sliderBar": "info ninepatch:2,2,0,0",
          "sliderBarMaxHeight": 4,
          "marginLeft": 14,
          "marginRight": 14
        }
      }
    }
  },
  "textboxes": {
    "default": {
      "rules": {
        "XS": {
          "font": "default",
          "textColor": "1,1,1",
          "background": "info ninepatch:12,12,12,12",
          "hoverBackground": "info ninepatch:12,12,12,12",
          "actionBackground": "info ninepatch:12,12,12,12",
          "disabledBackground": "info ninepatch:12,12,12,12",
          "paddingTop": 12,
          "paddingBottom": 12,
          "paddingLeft": 12,
          "paddingRight": 12,
          "marginTop": 0,
          "marginBottom": 0,
          "marginLeft": 0,
          "marginRight": 0
        }
      }
    }
  },
  "tabs": {
    "default": {
      "rules": {
        "XS": {
          "tabButtonStyle": "info",
          "previousTabButtonStyle": "info",
          "nextTabButtonStyle": "info",
          "buttonLabelStyle": "info",
          "buttonImageStyle": "default",
          "menuStyle": "info",
          "tabStyle": "info"
        }
      }
    }
  }
}

The Full buttons.atlas contains:


buttons.png
size: 2048,2048
format: RGBA8888
filter: Nearest,Nearest
repeat: none
Pill
  rotate: false
  xy: 2, 1583
  size: 379, 403
  orig: 379, 403
  offset: 0, 0
  index: -1
Pill_Pressed
  rotate: false
  xy: 2, 1178
  size: 379, 403
  orig: 379, 403
  offset: 0, 0
  index: -1
Start
  rotate: false
  xy: 2, 2
  size: 128, 58
  orig: 128, 58
  offset: 0, 0
  index: -1
Start_p
  rotate: false
  xy: 908, 1748
  size: 523, 238
  orig: 523, 238
  offset: 0, 0
  index: -1
audio
  rotate: false
  xy: 343, 356
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
audio-p
  rotate: false
  xy: 590, 616
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
back
  rotate: false
  xy: 969, 1222
  size: 243, 256
  orig: 243, 256
  offset: 0, 0
  index: -1
back_p
  rotate: false
  xy: 724, 1222
  size: 243, 256
  orig: 243, 256
  offset: 0, 0
  index: -1
fb
  rotate: false
  xy: 590, 356
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
fb-p
  rotate: false
  xy: 1408, 1468
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
forward
  rotate: false
  xy: 590, 98
  size: 243, 256
  orig: 243, 256
  offset: 0, 0
  index: -1
forward_p
  rotate: false
  xy: 837, 964
  size: 243, 256
  orig: 243, 256
  offset: 0, 0
  index: -1
info
  rotate: false
  xy: 1927, 1919
  size: 64, 67
  orig: 64, 67
  offset: 0, 0
  index: -1
info-p
  rotate: false
  xy: 343, 876
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
leaderboard
  rotate: false
  xy: 383, 1136
  size: 339, 370
  orig: 339, 370
  offset: 0, 0
  index: -1
leaderboard_p
  rotate: false
  xy: 2, 806
  size: 339, 370
  orig: 339, 370
  offset: 0, 0
  index: -1
noads-btn
  rotate: false
  xy: 343, 96
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
noads-btn-p
  rotate: false
  xy: 1161, 1488
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
rate
  rotate: false
  xy: 1655, 1468
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
rate-p
  rotate: false
  xy: 1680, 1728
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
remove_Ads
  rotate: false
  xy: 383, 1508
  size: 523, 238
  orig: 523, 238
  offset: 0, 0
  index: -1
remove_Ads_p
  rotate: false
  xy: 383, 1748
  size: 523, 238
  orig: 523, 238
  offset: 0, 0
  index: -1
restore-purchases
  rotate: false
  xy: 343, 616
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
restore-purchases-r
  rotate: false
  xy: 908, 1480
  size: 251, 266
  orig: 251, 266
  offset: 0, 0
  index: -1
share
  rotate: false
  xy: 590, 876
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
share-p
  rotate: false
  xy: 1433, 1728
  size: 245, 258
  orig: 245, 258
  offset: 0, 0
  index: -1
store_Button
  rotate: false
  xy: 2, 62
  size: 339, 370
  orig: 339, 370
  offset: 0, 0
  index: -1
store_Button_p
  rotate: false
  xy: 2, 434
  size: 339, 370
  orig: 339, 370
  offset: 0, 0
  index: -1

The confusing thing is, if i replace the path to my json file with UiTheme.DEFAULT_THEME_FILENAME everything works fine, so i guess the issue is somewhere around these files, but i've compared them to the files here https://github.com/mini2Dx/mini2Dx/tree/8524db12d3d751efbd21150d28ad5127fdec798d/ui/src/main/resources and they seem to be the same.

@tomcashman
Copy link
Contributor

The issue is that it can't find your texture atlas. Is it in the same directory as your json file?

@lukasknutti
Copy link
Author

In fact, it is. Here a simplified blueprint of my directory tree:

  • core
  • assets
    • ui
      • buttons
        - buttons.json
        - buttons.atlas
        - and all the plain images
  • desktop
  • ...

So is there something i'm missing, as i really don't see why it does not work...

@tomcashman
Copy link
Contributor

Did you try setting it to ui/buttons/buttons.atlas ?

@lukasknutti
Copy link
Author

Quite embarrassing to be honest, but i didn't. And after some bug fixes in my json file everything works now. thanks mate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants