I read a State<T> in a Deffered created in D...
# compose-desktop
x
I read a State<T> in a Deffered created in Dispatchers.Default and got this exception. Does this mean it is unsafe to read/write State and MutableState in threads other than the main thread? Or am I missing something here? Thanks
Copy code
java.lang.IllegalStateException: Method should be called from AWT event dispatch thread
	at org.jetbrains.skiko.SkiaLayer.needRedraw(SkiaLayer.awt.kt:427)
k
This is very short on detail. You’ll need to provide the full stack trace, and also ideally a small reproducer for this. In Swing / AWT (which is the windowing API behind Compose on Desktop) there are rules on what kinds of operations are not permitted off the EDT - event dispatch thread. So depending on what you do in that dispatcher, you might be changing the UI state off the EDT - which is where it gets to that check and exception.
x
@Kirill Grouchnikov Thank you for you response. It seems I am on my own for this one because the only place I can trigger this exception is is a specific part in my production code, which I can't not disclose 😞 .Basically, I was trying to mutate the state inside a rpc call (using grpc). Maybe grpc and its thread has something to do with this.
m
Generally using
State<T>
from concurrently is totally safe, it seems here you also do something else.
x
@mcpiroman yes, I was doing something weird in the code, just fixed it 🤕