Save states not functioning properly when sound flag is used
Hello, I've been testing out Pyboy with Pokemon Crystal, and was using the
--sound
flag to enable the sound. I used Z to store the save state which it did. But when I came back around and tried reloading it with the --sound
flag. the sound was gone and an error was present14 Replies
the library seems to be trying reference an invalid pointer/file
I've tried a few things now, and I cannot seem to replicate it on Mac and Linux. I can see you might be on Windows? But that should of course also work
And it works fine if you don't load a saved state?
Could you run PyBoy with
--log-level=DEBUG
and paste the whole output from the terminal?yeah, it works when I run an entirely new instance
Here's the debug statement
Nothing out of the ordinary
Could you try cloning the repo and inside the repo do
python3 -m pyboy ...
as you did before. It should give some more detailsah I'll try that, in a moment
also, the sound compatibility is still in beta right?
It's still in beta, but it shouldn't crash. Just not be perfectly accurate, and sometimes stutter a little
yeah
I might have an idea what's happening here
On load state, the cpu restores its cycle counter to what it was before, causing the sound device to try to process more samples than it's supposed to.
self.last_cycles
is initialized to 0 instead of the value of pyboy.mb.cpu.cycles
(which probably isn't loaded when the Sound object is made anyway)
to make matters worse, there's this:
I'm not sure why that's min
instead of max
for the number of samples to generate--I think we've gone back and forth on it before, but whatever the reason is, if nsamples
is greater than 2048, it will overrun the sample buffer.
Then the access violation is caused in Sound.enqueue_sound(self)
:
when SDL_QueueAudio(...)
tries to access a values indexed off of self.audiobuffer_p
that is outside of the buffer and possibly allocated memory.
I don't know when I'll have time to revisit --sound
🥲 but for now it should be sufficient to change that min
to max
on line 171, and test to make sure that doesn't break anything.I think the
min
is right. It bounds it to be ≤2048Oh right, right. I think I messed it up the first time too haha
Been a long week
Shoot, guess I don't have anything to offer here then
I also get confused with
min
/max
😅Best support thread ever
I’ll be waiting for your PR
I think I've inadvertently fixed this in the next version. I can only reproduce it on master
ah nice, good job!