Truth be told, I've heard about Zig being safer than C, but I did not know what it meant—mainly because I did not know why C is unsafe. Today I came across one of those scenarios. It stumped me for a couple of hours until I realized what was going on. Let me explain.
I've been wrestling with ALSA to play audio on my Window, which is just a Zig file. The audio was playing fine, but the program would crash as soon as the audio finished playing. The audio was completely fine—I could change the volume, rate, channels, and anything else for that matter. I do love to jump to conclusions, so when I saw the segmentation fault in the debugger, I was like, "I know what this is." Only I didn't; the memory was in scope and allocated.
I found the problem in the debugger when I unwrapped the calls to the system library. I realized PulseAudio, which was the default device selected when I opened a new audio handle, was trying to free the buffer. This is a big no-no. First of all, I don't want the buffer freed; second of all, Zig does not allow it. Boy, safety sure does come with a price.
So I then decided to go back to my initial approach of using an MMAP to write directly to the device memory until I realized why I had used the current approach. Turns out PulseAudio does not support it which I totally forgot about. So now I don't know what to do. Audio so far has been quite the joy ride turned grand theft auto.
I just realized I never really considered what people who do this kind of stuff do to get audio working. I'm going to do that now. I'm quite frustrated, but some part of me really enjoys this too.