pokepetter / ursina

A game engine powered by python and panda3d.
https://pokepetter.github.io/ursina/
MIT License
2.22k stars 326 forks source link

an Exception Error Caused in ursina's mouse.py #730

Open cloud1980 opened 3 weeks ago

cloud1980 commented 3 weeks ago

My Ursina application has runned normally for months on an Ubuntu 20.04 workstaion which can be visited by xrdp service. Sometimes the administrator uses the windows system's remote connector to check if it works well. THe Ursina version is 5.2.0. But today, one exception happed, maybe caused by "mouse" operation. The info in the terminator are as follows:

Traceback (most recent call last): File "/home/ndri/Crane_WenXiu/src/main.py", line 71, in app.run() File "/usr/local/lib/python3.8/dist-packages/ursina/main.py", line 241, in run super().run() File "/usr/local/lib/python3.8/dist-packages/direct/showbase/ShowBase.py", line 3330, in run self.taskMgr.run() File "/usr/local/lib/python3.8/dist-packages/direct/task/Task.py", line 553, in run self.step() File "/usr/local/lib/python3.8/dist-packages/direct/task/Task.py", line 504, in step self.mgr.poll() File "/usr/local/lib/python3.8/dist-packages/ursina/main.py", line 108, in _update mouse.update() File "/usr/local/lib/python3.8/dist-packages/ursina/mouse.py", line 234, in update self._picker.traverse(self.traverse_target) AssertionError: !cnan(r2) at line 181 of panda/src/mathutil/boundingLine.cxx

pokepetter commented 3 weeks ago

How can it be reproduced?

cloud1980 commented 3 weeks ago

The Ursina application has been running continuously for 24 hours a day without interruption for several months. Every one or two days, the administrator will remotely connect to check on it. This issue has only occurred once so far, so I also don’t know how to reproduce it.

The original code in "/usr/local/lib/python3.8/dist-packages/ursina/mouse.py", line 234 is

        if self.traverse_target:
            self._picker.traverse(self.traverse_target)

now I changed it as follows in order to catch some evidence:

        if self.traverse_target:
            try:
                self._picker.traverse(self.traverse_target)
            except Exception as e:
                print(e)

ChatGPT said "The expression !cnan(r2) shows that the code is checking whether the variable r2 is not a “Not-a-Number” (NaN) value. Variable r2 is NaN: cnan(r2) might be a function that checks whether r2 is NaN. If r2 is indeed NaN, then !cnan(r2) will fail, leading to an assertion error. You need to check whether there are any errors or unreasonable operations in the calculation process of r2 before the code reaches this line, such as division by zero, undefined mathematical operations, etc."

I suspect that the issue might be due to computational problems such as encountering a singular matrix that cannot be inverted during the pose transformation calculations for mouse operations, leading to this abnormal error.

pokepetter commented 2 weeks ago

This is probably a lower level error, in panda3d's collision library. There's some invalid math somewhere, like diving by 0 because something is scaled to 0 for example. It's kinda hard to figure out why it happens though.