Consider the following toy example of EventHandler used to implement dragging a point around in a Graphics:

DynamicModule[{v = {0, 0}},
 EventHandler[
  Dynamic@Graphics[{
     Circle[], PointSize@0.02, Tooltip[Point@v, "something"]
     }],
  {"MouseDragged" :> Set[v, MousePosition["Graphics"]]}
  ]
 ]

Everything seems to be working smoothly, and it does, as long as the Tooltip is not added. When a tooltip is added like in this example, a strange and somewhat inconsistent behaviour is observed.

Try to do the following:

  1. Mouse-drag the point to some position in the circle
  2. Release the point, and soon after (~1 second) start dragging the point again, and move it slowly in some direction.

You should observe that after a short period of moving the point slowly in the second phase, the graphics goes red, because for some reason MousePosition evaluated to None, which set v to None, which makes Graphics complain.

Hoping that you can reproduce this behaviour, it really looks like both steps above are necessary for this to happen. Moving the point always fast does not give problems, and also without the release-and-recatch action seem to be necessary to reproduce this.

Here is a gif showing this behaviour (I see this on v11.3): enter image description here

Is this some kind of weird bug in the way MousePosition works? How can this be avoided?

  • Can't reproduce it but my guess is it is because the entire Graphics is destroyed and recreated when v is changed, and sometimes you can catch that moment when there's None position. Unless you really need to keep it there I suggest to narrow the scope of Dynamic to minimum. Here Point@Dynamic@v. – Kuba Nov 10 at 19:31
  • @Kuba that would make sense, but then I don't get why it doesn't happen without the Tooltip – glS Nov 10 at 20:40
  • Maybe that was just the last straw on the camel's back. – Kuba Nov 10 at 22:37
  • I can not reproduce the problem documented in this question with V.11.3 on my system — MacOS 10.13.4. What OS are you using? – m_goldberg Nov 12 at 14:10
  • @m_goldberg ubuntu 18.04 – glS Nov 12 at 14:11

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.