hikaru-y / anki

Anki for desktop computers
Other
0 stars 0 forks source link

[I/O] Some event listeners are not removed when mask editor is unmounted #3

Open hikaru-y opened 1 year ago

hikaru-y commented 1 year ago

Some event listeners are not removed when the mask editor is closed

When the mask editor is closed, some event listeners are not deleted and continue to accumulate, leading to memory leaks.

マスク・エディタを閉じたときに、一部のイベントリスナーが削除されず蓄積し続け、メモリーリークに繋がります。

Screenshot ![io-event-listeners](https://github.com/hikaru-y/anki/assets/47855854/1683dee2-d2ac-4f96-bb28-fb30f0f2d3ab)

Causes

  1. https://github.com/ankitects/anki/blob/ff536254081fbbda48b56033e8e4fd80a66042e3/ts/image-occlusion/MaskEditor.svelte#L52-L62
    • I don't think anonymous event listeners can be removed unless we use AbortController, which is not available in Qt5.15.
    • Possible fixes
      • Name the function or use <svelte:window>
  2. https://github.com/ankitects/anki/blob/ff536254081fbbda48b56033e8e4fd80a66042e3/ts/image-occlusion/Toolbar.svelte#L43-L48
  3. Event listeners added via canvas.on(eventName, handler) are not removed when the mask editor is closed.
    • Possible fixes
      • If we create a new canvas every time we switch notes as we do now, we would need to call removeListeners() or dispose() when the component is destroyed. Alternatively, if we reuse one canvas all the way from opening the editor to closing it, we shouldn't have to care about the event listeners not being removed.

Some issues that arise when switching notes at high speed by holding down the up/down arrow keys or shortcut keys in the browser or by hitting them repeatedly

ブラウザで上下の矢印キーやショートカットキーを押しっぱなし、あるいは連打して高速でノートを切り替える際に起こるいくつかの問題点

The size of the canvas and image is sometimes set to the optimum size calculated for the image of the previous note (or possibly even earlier) rather than for the image of the current note.

キャンバスと画像のサイズが現在のノートの画像にたいするものではなく、一つ前のノート(あるいはもしかしたらさらに前の場合もあるかも)の画像に対して対して計算された最適サイズに設定されることがある

Holding down the up/down arrow keys or shortcut keys (Ctrl + P/N) in the browser to switch notes at high speed causes the following two errors

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'insertRule') Uncaught TypeError: Cannot read properties of null (reading 'clientWidth') After this error, the drawing tools on the left toolbar will not function properly

ブラウザで上下の矢印キーやショートカットキーを押しっぱなしにして高速でノートを切り替えると以下の2つのエラーが発生します。

Undo/redo

The change event is not dispatched when undo/redo is performed. Therefore, if the user closes the editor or switches to another note after undoing or redoing without performing an operation that dispatches the change event, the changes will not be saved.

アンドゥ、リドゥをする時にchangeイベントがディスパッチされません。したがってアンドゥ、リドゥした後にchangeイベントがディスパッチされる操作をユーザーがしないでエディタを閉じる、あるいは別のノートにスイッチすると変更が保存されません

The change event is not dispatched when undo or redo is performed. Therefore, if the user closes the editor or switches to another note after undoing or redoing without performing an action that would cause the change event to be dispatched, the undone or redone changes will not be saved.

取り消しややり直しを実行した時にchangeイベントがディスパッチされません。したがって、取り消しややり直しを実行した後にchangeイベントがディスパッチされる操作をユーザーがしないでエディタを閉じる、あるいは別のノートにスイッチすると取り消しややり直しをした変更が保存されません

When Edit current or Browse is opened (i.e. mode.kind===edit), if you click the undo button before making changes to an existing mask or adding a new mask, the existing masks will disappear and they will not be restored when you redo.

Edit currentあるいはBrowseを開いた時(つまりmode.kind===edit)、既存のマスクに変更を加える、あるいは新たにマスクを追加する前にアンドゥボタンをクリックすると、既存のマスク達が消えてしまい、リドゥをしてもそれらは復元されません。

When you open Edit Current or Browse (i.e. mode.kind===edit), the beginning of the undo history is a blank canvas, not a canvas with existing masks. Therefore, if you continue to undo to the end of the undo history, the masks that existed when you opened the editor will be lost, and they will not be restored when you redo.

Edit CurrentあるいはBrowse(つまりmode.kind===edit)を開いた時、アンドゥ履歴の最初には、既存のマスク達を伴ったcanvasではなく、まっさらなcanvasが記録されています。したがって、アンドゥ履歴の最後まで元に戻すを実行し続けると、エディタを開いた時点で存在したマスク達が消えてしまい、やり直しを実行してもそれらは復元されません。

In the Add dialog, the undo history is not reset when starting a new note after adding a note.

Addダイアログで、ノートを追加した後続けて新たにノートを作成し始める際にアンドゥ履歴がリセットされない。 In the Add dialog, the undo history is not reset when starting to create another note after adding a note.

If you create a polygon and then manipulate another object, the polygon disappears. The issue does not seem to occur in the Add dialog (KIND===add).

Fix some issues with undo/redo in mask editor; make undo/redo buttons reactive

The undo or redo button is now disabled when there is no action to undo or redo. The undo/redo button will now be disabled if there is no action that can be undone/redone. 今やアンドゥあるいはリドゥボタンはアンドゥ、リドゥできるアクションが無い時は無効化されます。


ポリゴンを作成し、それから他のオブジェクトを操作するとポリゴンが消えてしまう。この問題はAddダイアログ(kind===add)では起こらないようだ。

hikaru-y commented 1 year ago

anki/pull/2485#issuecomment-1643405353