3
$\begingroup$

Bug introduced in 9.0 or earlier, persisting through 13.2 or later


With the following Dynamic cell, I can reproducibly crash Mathematica, so do not try this unless you have saved all your work!

l=1;
Dynamic[Sin[l = l + 1]]

This will harmlessly run forever, or until you try to right-click on the dynamic output (to get the context menu and perhaps to copy the current value). When you right-click on it, Mathematica crashes.

Is there a simple way to avoid or catch this error before it occurs?

Edit

I also see this crash when literally using the example from the documentation for Dynamic (under "Applications"):

{Trigger[Dynamic[x, (a = FractionalPart[#]; x = Round[#]) &], {0, 
   Infinity}], 
 Dynamic[{Quotient[x, 60], Mod[x, 60], SetPrecision[10 a, 2]}]}

and again trying to right-click. So it's not like I'm doing something outlandish here.

Edit 2 The link Szabolcs found does indeed answer my question:

EventHandler[Dynamic[Sin[l = l + 1]], {"MouseUp", 2} :> Null]

seems to prevent the crash.

$\endgroup$
12
  • $\begingroup$ You should definitely report the crash to WRI. $\endgroup$
    – Szabolcs
    Commented Feb 19, 2012 at 19:22
  • $\begingroup$ You'll be interested in this: groups.google.com/d/topic/comp.soft-sys.math.mathematica/… $\endgroup$
    – Szabolcs
    Commented Feb 19, 2012 at 19:35
  • $\begingroup$ @Szabolcs Thanks, that must be the same error, and the fix works. Do you want to post this as an answer? $\endgroup$
    – Jens
    Commented Feb 19, 2012 at 19:41
  • $\begingroup$ I can't reproduce it on V9. I'll try later on 9.0.1.0. $\endgroup$
    – Kuba
    Commented Mar 25, 2014 at 16:45
  • $\begingroup$ @Kuba, yes, I think this was fixed in the meantime - I don't see the crash on 9.0.1 anymore. But in your question here, the fix seems to work. $\endgroup$
    – Jens
    Commented Mar 25, 2014 at 16:49

1 Answer 1

2
$\begingroup$

Based on this MathGroup post describing a similar crash, the right click can be caught and discarded like this:

l = 1;
EventHandler[Dynamic[Sin[l = l + 1]], {"MouseUp", 2} :> Null]

This won't let you copy the value, but it will prevent crashes due to accidental right clicks.

You can obtain the value by evaluating l as a different input.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.