Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
    
You should definitely report the crash to WRI. –  Szabolcs Feb 19 '12 at 19:22
    
You'll be interested in this: groups.google.com/d/topic/comp.soft-sys.math.mathematica/… –  Szabolcs Feb 19 '12 at 19:35
    
@Szabolcs Thanks, that must be the same error, and the fix works. Do you want to post this as an answer? –  Jens Feb 19 '12 at 19:41
    
I can't reproduce it on V9. I'll try later on 9.0.1.0. –  Kuba Mar 25 at 16:45
    
@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. –  Jens Mar 25 at 16:49
show 2 more comments

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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