ankidroid / Anki-Android

AnkiDroid: Anki flashcards on Android. Your secret trick to achieve superhuman information retention.
GNU General Public License v3.0
8.5k stars 2.21k forks source link

[Bug] An error will be triggered when rating a card while the AnkiDroidJS API is processing `api.ankiSetCardDue()` #15936

Closed ChuckieChen945 closed 3 weeks ago

ChuckieChen945 commented 6 months ago
Reproduction Steps

I can’t reproduce this error because the timing of triggering is very important. But I have some clues about this Bug and a video of triggering this Bug:

I have a deck for practicing English listening. The script in the card template is set to: automatically display the answer, play the audio on the back of the card twice, and then execute api.ankiSetCardDue(0), Set the card’s due date to today (this can achieve the effect of looping the audio in the deck: you can listen to the audio in the entire deck while doing housework and other free time, you don’t have to rate a single card immediately, and you won’t get stuck on a card; if I can free my hands, I will rate the card that is playing). When the audio playback ends, if I happen to press the rate button when AnkiDroid executes api.ankiSetCardDue(0), an error will occur. See the video below:

https://github.com/ankidroid/Anki-Android/assets/29732324/5b599136-f5ad-4d0b-a5e0-0dfb16d57913

(The error is at the 30th second in the video. I have undone the answer card several times in the video, but I think this should not affect it.)

Depending on the timing of the trigger, sometimes it is “not at top of queue” (see the above video), sometimes it is “card was modified” (see the picture below, and “card was modified” is triggered more frequently), this may be related to the internal processing steps of api.ankiSetCardDue() (I'm not sure).

Screenshot_20240314_155312_com ichi2 anki

The timing of the trigger is very important, so it is difficult to deliberately manually trigger. I have tried to execute api.ankiSetCardDue(0) and buttonAnswerEase3() in the card template in sequence, but I have not been able to trigger this error. Perhaps rating through the AnkiDroidJS API and manual rating have different mechanisms(I'm not sure). Checking the source code to see if it can correctly handle the situation where the user rates the card during the execution of api.ankiSetCardDue() may get further information about this Bug.

Expected Result

Correctly handle the situation where the user manually rates the card while the program is executing api.ankiSetCardDue().

Actual Result

Throw “not at top of queue” or “card was modified”.

Debug info
AnkiDroid Version = 2.17.5 (1c1aa94ec466f37d33fd2f75020d9f9021ac811e)

Backend Version = 0.1.34-anki23.12.1 (23.12.1 1a1d4d5419c6b57ef3baf99c9d2d9cf85d36ae0a)

Android Version = 10 (SDK 29)

ProductFlavor = full

Manufacturer = HUAWEI

Model = MXW-AN00

Hardware = mt6873

Webview User Agent = Mozilla/5.0 (Linux; Android 10; MXW-AN00 Build/HONORMXW-AN00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.105 Mobile Safari/537.36

ACRA UUID = 82400b65-bd87-4883-a1f6-b911150f725b

Crash Reports Enabled = true
Research

Enter an [x] character to confirm the points below:

krmanik commented 6 months ago

I will investigate the issue.

krmanik commented 5 months ago

@ChuckieChen945 Can you share the deck here?, if it is private deck then you can email it me krmanik@outlook.com.

ChuckieChen945 commented 5 months ago

@ChuckieChen945 Can you share the deck here?, if it is private deck then you can email it me krmanik@outlook.com.

This is indeed my private deck. I have sent it to krmanik@outlook.com, with the email subject as “AnkiDroid issues 15936 related deck”. I apologize for not attaching the relevant deck at the first time as I thought this was a relatively easy issue to solve. To better demonstrate this issue, I recorded a few unedited videos. By the way, this time I used AnkiDroid 2.18alpha8 and AnkiDroidJS API 0.0.3. This issue still exists in the latest alpha release. In the following videos, I am not really studying Anki cards, but just trying to trigger this issue as efficiently as possible, so I set the audio speed very fast and only play it once.

https://github.com/ankidroid/Anki-Android/assets/29732324/9a47ae25-13f5-4843-bbb0-05a41cde724a

In this video, this issue is triggered at the 60th second. Turning on the slide switch in the lower right corner of the card will fix the current card, which is no different from the general use of Anki; turning off the slide switch in the lower right corner of the card will execute api.ankiSetCardDue(0) after the audio in each card is played, so it can achieve the effect of looping the audio in the deck.

https://github.com/ankidroid/Anki-Android/assets/29732324/0e4c7d77-633a-49ff-a6d6-3b0c4e7a67e2

In this video, this issue is triggered at 1 minute and 36 seconds.

https://github.com/ankidroid/Anki-Android/assets/29732324/411543ba-76f2-4427-87fa-f368d58433b0

In this video, this issue is triggered at the 30th second.

I also know that this issue is currently difficult to be triggered stably, so if you need more information, you can contact me at any time.

krmanik commented 5 months ago

I have got the mail, I will debug comment info here.

ChuckieChen945 commented 4 months ago

Some background related to this issue: https://forums.ankiweb.net/t/feature-request-add-an-api-ankiunburydeck-js-api-to-ankidroid-to-implement-the-playlist-loop-feature/45624/1

github-actions[bot] commented 1 month ago

Hello 👋, this issue has been opened for more than 3 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically