vpython / vpython-jupyter

3D visualization made easy
MIT License
138 stars 65 forks source link

version7.6.3: error when executing scene.camera.follow(None) #197

Closed horstjens closed 2 years ago

horstjens commented 2 years ago

using Ubuntu Linux 21.10, python 3.9.7, vpython version 7.3.6 jupyter: after upgrading to vpython version 7.6.3, i got this error when my program tries to execute the scene.follow(None)"command:

The error is reproducable using idle or a python shell:

>>> import vpython as vp
>>> vp.scene
<vpython.vpython.canvas object at 0x7f059eaabbb0>
>>> vp.scene.camera.follow(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/vpython.py", line 2937, in follow
    self.addmethod('follow', obj.idx)
AttributeError: 'NoneType' object has no attribute 'idx'
>>> 

Is this a re-introduced error from version <7.6.1 ? If i run a bigger vpython program, i got those error messages below. The program still continues to work, but the camera is still following the object from the last camera.follow command, it is ignoring the "scene.camera.follow(None)" command.

my current workaround is to let the camera follow an non-moving object


Task exception was never retrieved
future: <Task finished name='Task-189' coro=<WSserver.onMessage() done, defined at /home/horst/.local/lib/python3.9/site-packages/vpython/no_notebook.py:181> exception=AttributeError("'NoneType' object has no attribute 'idx'")>
Traceback (most recent call last):
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/no_notebook.py", line 214, in onMessage
    await loop.run_in_executor(None, GW.handle_msg, msg)
  File "/usr/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/vpython.py", line 392, in handle_msg
    obj._bind()
  File "/home/horst/code/vpython/flugzeug2.py", line 34, in follow_plane_no
    Game.scene1.camera.follow(None)
  File "/home/horst/.local/lib/python3.9/site-packages/vpython/vpython.py", line 2937, in follow
    self.addmethod('follow', obj.idx)
AttributeError: 'NoneType' object has no attribute 'idx'
BruceSherwood commented 2 years ago

Thanks much for the report. This works correctly in Web VPython but is a bug in the vpython module used with installed Python.

BruceSherwood commented 2 years ago

I found the bug, which will be fixed the next time there is a release of the vpython module. In the meantime, starting at line 2936 in site-packages/vpython/vpython.py, replace the def follow function with this:

def follow(self, obj):    ## should allow a function also
    if obj is None:
        self.addmethod('follow', 'None')
    else:
        self.addmethod('follow', obj.idx)