Picking tutorial wrong?

the tutorial is
http://www.xith.org/tutes/GettingStarted/html/picking.html

By my counts the mutex stuff will allow many mouse events to go past the rendering thread. OK for this example, but if you want to do something like mouse panning then you cant afford to lose a single mouse event. It could be the mouse release event.
Here is my bodged solution


synchronized (pickParamsMutex) {
                    while (mutexCount > 0) {
                        try {
                            if (e.getID() == MouseEvent.MOUSE_MOVED) {
                                return;
                            }
                            if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
                                return;
                            }
                            pickParamsMutex.wait();
                        } catch (InterruptedException e1) {

                            System.out.println("waiting AWT thread woken up");
                        }
                    }
                    mutexCount++;

                }
                lastMouseEvent = e;

Combined with


synchronized (pickParamsMutex) {

            state = state.changeState(state, lastMouseEvent, canvas);
            mutexCount--;
            pickParamsMutex.notify();
        }

this way all incoming mouse event are stopped at the top and are only let through one at a time. I have a supsicion the order may not be preserved though. So those who need it might need a list or something. I have also in my example thrown out the dragged and moved if they have to be delayed. Some will still get through, its jsut so I don’t get a massive pilup of those inessential events, enough will get through to my underlying behavour

Tom

yeah ok. That post is rubbish. The code does not quite work either. But hopefully you will get my drift :slight_smile:

well. It does actually work as it is. But the mutex count does noting meaningful. So ignore that bit and you will be ok.
Right its 2.30 a.m. I should go to bed before I write too much other rubbish

If you don’t want to lose events, you can save them in a list instead of just setting a boolean flag. For the tutorial this isn’t a problem. The synchronizing makes sure the rendering thread isn’t interrupted while executing the picking code.