-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Rare NPE in GlyphLayout #7582
Comments
Most likely this is related to threading. Are you doing any multithreading/http requests and mutating state/labels without making sure those mutations are running on main thread? |
Yes there is stuff happening in the background but I am running UI related code only on the main thread because I know that libgdx is not threadsafe. |
Yeah, it definitely sounds like a multithreading issue. It can be super rare. I would verify you aren't mutating label states from another thread, you can do this even without getting a crash.
You can just ThreadUtils.setGdxThread(Thread.currentThread()), in your create method of application listener. Then use gdxThreadSafetyCheck() anywhere you suspect it may be happening. You can do this in conditional breakpoints on libgdx methods too with your debugger if you have lots of different access points. |
Looks interesting, I will certainly look into it, thank you. |
I want to advocate for more methods that allow use in a parallel context. E.g. FontCache text can be set using an explicit GlyphLayout instance preventing access to the non thread safe static GlyphLayout pool. However, GlyphLayout does not offer such access to give the user control over how GlyphRuns get pooled. An option could be to let each GlyphLayout store it's own reference to a glyph pool that can be set by the user. If you wonder why this is useful in the first place. I am generating a lot of mesh data, including ones for text, in some worker threads. Having to do this explicitly in the main thread would be a bummer. |
Smiles, nods, and points at TextraTypist... TextraTypist doesn't use any static pools, though I'd stop shy of calling it fully-thread-safe at this point. It uses a different technique for storing text internally, and this allows lots of additional markup to be used for various styling. For example, libGDX can do I've been working on version 1.2.0 for a while now, and I'm not 100% sure when it can be released, because I've been thinking and saying "soon" for a month now or more. I might mark it 2.0.0, because it's a big improvement to usability in general, and some config from 1.1.0 needs changing (mostly because special config is needed less often). It isn't a tiny change to go from a game that uses GlyphLayout and BitmapFont internals to one that uses TextraTypist, so obviously this isn't something to try just before you release! The docs could also use work for the patterns of class use and interactions between classes, but the JavaDocs are rather thorough at least. If you decide to use TextraTypist, let me know if there are features I can add! |
Thanks, TextraTypist definitely looks cool. Though, as you said, in my case it's just easier to copy libGDX' code to make the necessary changes and I don't want to add just another library for this seemingly small requirement. Besides that, I don't think it provides raw text mesh data like BitmapFontCache.getVertices(). |
This PR basically serves as a solution to libgdx#7582 by allowing the user to implement custom pooling mechanic that could for example allow for thread safe use
I have an Android app in the Play Store.
Rarely I see exceptions like this in the Google Play Console:
or:
or, maybe related:
It happens in different labels, but only in labels, and I'm not able to reproduce it.
libgdx version: 1.12.1
Any idea?
The text was updated successfully, but these errors were encountered: