Crash in buffer_locksamples when changing the filename argument of the buffer

Michael Norris's icon

Hi there — I’m working on a Max/MSP external that processes a buffer of sound. I have a crash in buffer_locksamples that only occurs if the user changes the filename argument of the buffer that is being referenced while the external is running.

For instance, my [buffer~] object is set to ‘buffer~ myBuffer jongly.aif’. If I go in and change it to ‘buffer~ myBuffer duduk.aif’, while my external is running, I get the crash in this second line

t_buffer_obj *buffer = buffer_ref_getobject(x->bufferRef);
bufferPtr = buffer_locksamples( buffer );

My external never receives a buffer_changed notification — it just crashes with a EXC_BAD_ACCESS error.

Any thoughts?

Michael Norris's icon

SOLVED
For anyone else who has had this problem, here’s the solution:

The issue is a bit weird, but is due to an undocumented notification that is sent to the external. I had assumed that if the buffer’s filename was changed, then I should receive a “buffer_modified” notification. I was ignoring every other notification — i.e. I was returning 0 at the end of my notify routine.

However, it turns out that when the buffer filename is changed, there are in fact some notifications sent, but they are not ‘buffer_modified’. So what you *actually* need to do, to stop the crash — and the correct way to deal with this is shown in the sample projects, but I hadn’t quite appreciated the importance of it — is that you need to forward *all* notifications to the buffer_ref_notify routine — i.e. you should never return 0 at the end, always: return buffer_ref_notify(x->bufferRef, s, msg, sender, data);