"corrupted double-linked list" error when switching Samples


SDK version 2.0 on Linux

I think I've narrowed it down enough to where I can be pretty certain this is where the bug is. After playing a Sample completely using a sequence, then replacing the Sample by using either track:setInstrument() or synth:setWaveform(), Playdate (in the simulator and on hardware) throws a "corrupted double-linked list` error and then freezes for up to 10 seconds, or it throws a "SoundSource (hex address) doesn't have a lua wrapper" error. Sometimes it does this, sometimes it does not.

Here's a simplified version of the code:


Here is one of the crash logs:

   r0:00000001    r1:00000001     r2:00045400    r3: 40012c00
  r12:0000000a    lr:080b3103     pc:080b2d08   psr: 21000000
 cfsr:00000082  hfsr:00000000  mmfar:ffd8ffef  bfar: ffd8ffef
heap allocated: 1695136
Lua totalbytes=286594 GCdebt=-2000 GCestimate=280034 stacksize=42

This looks like it might be the same bug as Crash: Track:setInstrument() while a note is playing (missing Lua Wrapper) I don't have a fix in for that yet, but I'll take another look at it now and see if I can get something together for you to test.

1 Like

Here's a Linux version of the test build I posted in that other bug just now: Dropbox - File Deleted - Simplify your life Mind giving it a test and see if it fixes the problem? If you want to test on the device, just send me your serial # and I'll put you in a test cohort.

The issue still persists, but I have a little more information on the error (you probably are already aware of this, sorry in advance if you are).

I used gdb on the Simulator and got this once it crashed:
0x00005555559660f4 in AudioSample_release ()

So there must still be an edge case we're not handling properly. :frowning: Can you send me a pdx that demonstrates this? Source shouldn't be necessary. I tried to put something together following your outline above but it didn't crash.

Sure, this should cause the error (with source code in case you need it). Pressing A should crash the Simulator.

error.zip (93.2 KB)

1 Like

Aha, got it. It's a similar problem to the others but in a different place. Here the bug is that synth:copy() doesn't know anything about the specific type of synth so it does a plain copy of the underlying data. In this case we wind up with two references to the sample without bumping its retatin count; then when you replace the sample in the copy its retain count drops to zero and it gets freed even though there's still a reference to it. I've added a custom copy function in the implementation to fix this. In the mean time, you can work around it by not copying a synth with a sample set on it, either via synth.new(sample) or synth:setWaveform(sample).

1 Like

Awesome! Thanks for looking into that :playdate: