Gustaf-C / anki-chinese-support-3

Anki add-on providing support for Chinese study
https://ankiweb.net/shared/info/1752008591
GNU General Public License v3.0
26 stars 7 forks source link

Crashes on closing Anki #42

Closed soliviantar closed 2 months ago

soliviantar commented 7 months ago

When closing Anki, there's an error message and Anki won't close. After closing the error window, the user can close Anki normally. (Haven't tested on 23.10)

Error message:

Error
An error occurred. Please start Anki while holding down the shift key, which will temporarily disable the add-ons you have installed.
If the issue only occurs when add-ons are enabled, please use the Tools > Add-ons menu item to disable some add-ons and restart Anki, repeating until you discover the add-on that is causing the problem.
When you've discovered the add-on that is causing the problem, please report the issue to the add-on author.
Debug info:
Anki 2.1.66 (70506aeb) Python 3.9.15 Qt 6.5.2 PyQt 6.5.2
Platform: Windows-10-10.0.22621
Flags: frz=True ao=True sv=3
Add-ons, last update check: 2023-11-16 19:03:31
Add-ons possibly involved: ⁨Chinese Support 3⁩

Caught exception:
Traceback (most recent call last):
  File "aqt.main", line 1162, in closeEvent
  File "aqt.main", line 536, in unloadProfileAndExit
  File "aqt.main", line 511, in unloadProfile
  File "_aqt.hooks", line 4012, in __call__
  File "anki.hooks", line 34, in runHook
  File "C:\Users\user\AppData\Roaming\Anki2\addons21\1752008591\gui.py", line 97, in unload_menu
    for menu in mw.custom_menus.values():
AttributeError: 'AnkiQt' object has no attribute 'custom_menus'
Gustaf-C commented 7 months ago

Are you able to reproduce this consistently?

soliviantar commented 7 months ago

@Gustaf-C yes, this happens every time. But I think it might be an interefetence with another addon though.

soliviantar commented 7 months ago

Seems to be caused by anki-morphs addon (which crashes on startup since the last update). Disabling it prevents this error from happening.

kieranlblack commented 7 months ago

I took a glance at this earlier. The way the addon is setting up the menus right now isn't great. My guess is the anki-morphs addon you mentioned was being loaded before the chinese support addon and when it crashed during the profile_did_open hook, the chinese support addon didn't get to run it's hook to do some setup. This resulted in the menu for chinese support not being initialized and so cleanup was failing in the profile_will_close hook.

Gustaf-C commented 7 months ago

While an easy fix for this is possible (add the offending code to a try block) that would also cause a silent failure where the chinese support menu wouldn't appear without any apparent reason. At least now we do get an indication that something is wrong. Since the issue is caused by another addon crashing, and not an actual conflict, I think I'll let this be for now.

kieranlblack commented 7 months ago

We should probably add it to the todo list to change how the menus are set up, injecting our own property onto the mw object is a surefire way to have something go wrong, and a brief glance at some other addons tells me this way is a little dated.

When I next have time I can make an issue for it so we can keep track of what needs to be done.

Gustaf-C commented 2 months ago

Closing this since the problem is due to another addon. A potential fix is tracked in #78.