Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinity loop in spcProcessStream #226

Open
daniel-starke opened this issue Jul 28, 2023 · 9 comments
Open

Infinity loop in spcProcessStream #226

daniel-starke opened this issue Jul 28, 2023 · 9 comments

Comments

@daniel-starke
Copy link
Contributor

I experience sporadic infinity loops in spcProcessStream using pvsneslib c414bcd.
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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Owner

alekmaul commented Jul 29, 2023

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
Copy link
Contributor Author

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
Copy link
Contributor Author

I took a look at #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
Copy link
Contributor Author

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

  • implement a timeout in the CPU code which waits for the SPC700 to be ready by counting the loop iterations
  • reset the SPC700 state if a timeout has been detected

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

@alekmaul
Copy link
Owner

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants