A question about mouse and key events


I once had this problem with processing:

In processing, event handlers would kick in anytime so If you alter data that was being used in a draw operation, things would fail. It was like the events were being handled in a different thread, and you were able to change the data the draw routine was using as things were being drawn on screen so you needed to take extra measures. At least this was my observation.

In openframeworks, I suspect, this is not the case, I can change some stuff in mouse-keyboard event handling routines and they seem to cause no problems. Is this the safe way to do things? Or should I use event handlers as flag-setters that would be checked in every update operation as in processing?


quickly - yes, all the callbacks (update, draw, keyPressed, keyReleased, mouseMoved, etc) are synchronized, meaning, you will never get an event callback in the middle of a draw, etc. you manipulate data without worry –

threads, on the other hand, are not, then you will want to look at things like mutexs, because even boolean variables are not good enough to prevent collision. java has a threading keyword synchronized which prevents this, but c++ sadly doesnt. threads are helpful but very hard to work with for that reason. (we even made the thread example black, because it’s a “dark” art, :slight_smile: )

hope that helps !

That is good to know zach, thanks.
That means that, less housekeeping needs to be done.