BruceSherwood / vpython-jupyter

This repository has been moved to https://github.com/vpython/vpython-jupyter
64 stars 33 forks source link

Fix problem when set "rate" too large #24

Closed qazwsxedcrfvtg14 closed 7 years ago

qazwsxedcrfvtg14 commented 7 years ago

When set "rate" too large and ploting a gcurve in graph in the same time will cause "list index out of range" at "commcmds[L]" The code will cause this problem: http://codepad.org/sbe1Af73 Error message: http://i.imgur.com/5HlM84y.png

BruceSherwood commented 7 years ago

If I merely change "while True:" to "while t < 1000:" the program does not give an error, so the problem isn't simply that the rate argument is too large. The problem has something to do with plotting a large number of graph points in a very short time.

qazwsxedcrfvtg14 commented 7 years ago

I found the problem is plotting a large number of graph points in a very short time will cause "commcmds" bigger then baseObj.qSize*2 at here:     for m in ob.methodsupdt: # a list          if 'attr' in commcmds[L]: del commcmds[L]['attr'] # if left over from previous use of slot          method = m[0]          data = m[1]          commcmds[L]['idx'] = ob.idx         commcmds[L]['method'] = method         if method == 'add_to_trail': data = data.value         commcmds[L]['val'] = data         L += 1 I think better solution is sending commcmds before it geting too large. So I add:     if L > baseObj.qSize:         baseObj.glow.comm.send(encode_attr(commcmds[:L])) # Send attributes and methods to glowcomm                 L = 0 after L += 1

BruceSherwood commented 7 years ago

Implemented the fix. Thanks!