I am developing a game on android and i (obviously) need to make variables changes/calculations in the GL thread when events are coming from the main thread. I tried to implement sensor detection and it was ok, but when i tried to print the xyz values on the emulator screen, the program crashes. If i don't print them, it's ok. If i try to use the values in other ways it crashes too. So the only way to avoid the crash is not to use the sensor values at all. I think that it's because when i use the values in one thread (gl thread), in the same moments the main thread wants to update them so it's a conflict.
What should i do in order to avoid this conflict? I tried to use semaphors, but it didn't solve the problem? Maybe i used them in the wrong way.. Can someone post a solution to this problem (shared variables) and tell me how to use the actual data of the sensor?
edit: I tryed to use synchronized methods, but the problem still remains. I am wondering if Android implements the synchronized methods or it's a broken feature?
edit 2: I tried to use queueEvent(new Runnable()) like the documentation suggests and i still get the crash as soon as i use the shared variable... it's just crazy
edit 3: Sorry, it was my fault, actually i was using a non allocated reference in that function.. so it was not the synchronization's fault