-
Notifications
You must be signed in to change notification settings - Fork 72
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
assets MUST NOT be loaded in static code #42
Comments
Is this still an issue after #43 got merged? (I see you moved the Also regarding the Klooni1010/core/src/io/github/lonamiwebs/klooni/Klooni.java Lines 46 to 47 in ef2fb8f
Sure, it's static, but it's not loading anything. It defaults to Klooni1010/core/src/io/github/lonamiwebs/klooni/Klooni.java Lines 82 to 95 in ef2fb8f
So, is this still wrong? |
The text is according to your TODO that have been there before. I did'n have any look into it beside the code of SkinLoader. As to to the comment in Line 89 says it is a singleton, you should not allow public write access to it and use a public getter ... and have a look if that's really a performance hit or not ;) As it isn't loaded that early there's no need for static at all. If other classes need access, they should simply know Klooni. This would lead to more refactoring, ie. making the cellTexture a parameter of Cell.draw or supplying it at cell creation and changing the parameter of set to the already resolved texture to having Cells and maybe other to not needing to know Klooni. Alternatively you could have a private static variable to store the Klooni instance and supply it with a public static getter. ... much changes and I don't see a practical benefit now. As a big difference to effects you only have one Theme class and there's no need to change as long as that one size fits all. |
There are issues when loading asses in static code as that is exposed to a race condition. Loading assets with SkinLoader must not happen before class Klooni is initiated. In other cases Gdx.graphics will be null. It happens that this condition is accidently met for the current state of the code.
The order classes are loaded and initialized is subject to the class loader involved and that may change in the future, especially as this is an Android app and Google is experimenting much with it's runtime.
There are more reason to not load assets in static code, ie. error handling and the like.
Example of issues (initiate effects in static code from class Klooni):
SkinLoader static
Exception in thread "main" java.lang.ExceptionInInitializerError
at io.github.lonamiwebs.klooni.effects.WaterdropEffectFactory.(WaterdropEffectFactory.java:38)
at io.github.lonamiwebs.klooni.Klooni.(Klooni.java:46)
at io.github.lonamiwebs.klooni.desktop.DesktopLauncher.main(DesktopLauncher.java:34)
Caused by: java.lang.NullPointerException
at io.github.lonamiwebs.klooni.SkinLoader.(SkinLoader.java:43)
... 3 more
The text was updated successfully, but these errors were encountered: