alekmaul / pvsneslib

PVSnesLib : A small, open and free development kit for the Nintendo SNES
MIT License
798 stars 70 forks source link

Infinity loop in spcProcessStream #226

Open daniel-starke opened 11 months ago

daniel-starke commented 11 months ago

I experience sporadic infinity loops in spcProcessStream using pvsneslib c414bcd9. The issue occurs in snesmodwla.asm line 1136 and 1209 when it waits for the write to the audio IO to complete. I have also experience this issue in 862adbf for snesmodwla.asm line 1209.

The issue occurs for Bomb'n'Break when built with audio support (make HAS_BGM=1 HAS_SFX=1). Please find attached here a version with the audio files from pvsneslib: audio-files.zip, binaries.zip

Changing the audio files does not make any difference.

Here is a screenshot of an error case taken with BSNES plus 05 x64: bug-snesmodwla asm-line1209-c414bcd9 The loop does not complete.

The issue could also be observed in snes9x 1.62.3.

Any advice on how to analyze this issue is highly appreciated.

daniel-starke commented 11 months ago

It appears to be unrelated to the background music and happens also if only sound effects are compiled in and not background music.

daniel-starke commented 11 months ago

The first time I run spcPlaySound() the sound effect is always not playing properly. Sometimes it ends early, sometimes it repeats the start. This appears to be the case only in PAL (COUNTRY $02) mode, not in NTSC (COUNTRY $01) mode and only for the first time spcPlaySound() is being called. Nevertheless, the issue in question happens also in NTCS mode.

alekmaul commented 11 months ago

I think it is a memory issue when the brr file is too large. I need to check but I need time... The problem is not where you are checking your code but on SPC700 side. The spc700 hangs so never replies to the main CPU, which is the reason why you have an infinite loop... Check the SPC700 code if bsnes can do that (i did the check with no$sns), you will see that the PC is nowhere... By the way, I think your issue is duplicated, we have another one about this problem (but it's ok, leave your issue open ;) .

daniel-starke commented 11 months ago

My brr file is only 3573 bytes and I allocated 18 sound regions for it. Is there a way to work around this to see if this is really the issue?

P.S.: I have one case where this is true and one where both are stuck in a loop.

The case you have mentioned with SPC700 at a wrong PC: cpu smp

And the other case with both stuck in a loop: cpu smp

daniel-starke commented 11 months ago

I took a look at https://github.com/alekmaul/pvsneslib/issues/164. Most likely a duplicate of it. I think we got two issues: timing and invalid memory access But I have not enough in-depth knowledge of the sound driver to debug this.

daniel-starke commented 11 months ago

I propose the following workaround to be implemented in pvsneslib until the actual issue is fixed:

This will probably create sound glitches every now and then by prevents the game from freezing. What do you think?

alekmaul commented 11 months ago

well, i don't know. I think it is better to try to find and fix the bug. do you have a rom who is doing the bug everytime ? your "timing issue" is strange, i nver encounter this case of bug, evrytime it was a memory access issue.

daniel-starke commented 11 months ago

Unfortunately, this issue appears only sporadically. That is why I assume a timing issue. Fixing the bug it obviously the better solution. However, for the time being the workaround would make the issue less critical.

daniel-starke commented 11 months ago

Maybe the memory issue is related to the observation that the first time a sound is played in PAL mode it is always distorted. You can easily check this by changing the tada example to PAL (COUNTRY $02 in hdr.asm)