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

DynamicModule[{v = {0, 0}},
     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?

  • $\begingroup$ 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. $\endgroup$ – Kuba Nov 10 '18 at 19:31
  • $\begingroup$ @Kuba that would make sense, but then I don't get why it doesn't happen without the Tooltip $\endgroup$ – glS Nov 10 '18 at 20:40
  • $\begingroup$ Maybe that was just the last straw on the camel's back. $\endgroup$ – Kuba Nov 10 '18 at 22:37
  • $\begingroup$ 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? $\endgroup$ – m_goldberg Nov 12 '18 at 14:10
  • $\begingroup$ @m_goldberg ubuntu 18.04 $\endgroup$ – glS Nov 12 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.