I’m writing some iOS code, and I noticed I get occasional errors when I write the memory used by a vertex array in a ‘touchevent’ callback (memory access violation).
I believe touch events come in on a separate thread, so, if touchevents result in a change to the vertex arrays, I will need to queue a message that is to be picked up by the main thread (that does all the rendering) to make the needed change to the vertex array.
It should be fairly easy to root out all calls to functions that write graphics memory. However as a safety I want to check what thread I’m on (main thread or not) in certain subroutines (so the bug doesn’t insidiously creep back in again).
Is there a way in iOS to programmatically check what thread I’m on (main thread or not)?
The following snippet will log if you are on the main thread or not.
with this bit of code.
answering your question