Skip to content

AudioStream constructor #290

@akiriwas

Description

@akiriwas

I may have found another potential issue with the AudioStream class. The AudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) constructor currently just calls the Load() member function. However, the first thing that the Load member function does is call Unload which leads to a SEGFAULT:

#0  0x00007ffff7a3cbe0 in main_arena () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007ffff7eb7deb in ma_resampler_uninit () from /usr/local/lib/libraylib.so.500
#2  0x00007ffff7eb7fc8 in ma_data_converter_uninit () from /usr/local/lib/libraylib.so.500
#3  0x00007ffff7ee0e0b in UnloadAudioBuffer () from /usr/local/lib/libraylib.so.500
#4  0x00007ffff7ee366f in UnloadAudioStream () from /usr/local/lib/libraylib.so.500
#5  0x0000555555587048 in raylib::AudioStream::Unload (this=0x7fffffffdd18) at /usr/local/include/AudioStream.hpp:93
#6  0x0000555555587115 in raylib::AudioStream::Load (this=0x7fffffffdd18, SampleRate=44100, SampleSize=16, Channels=2) at /usr/local/include/AudioStream.hpp:207

As a work around for now, I've modified the constructor to not call Load but to do what Load would do:

    AudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels = 2) {
        set(::LoadAudioStream(sampleRate, sampleSize, channels));
        if (!IsReady()) {
            throw RaylibException("Failed to load audio stream");
        }
    }

This may not be the best long term solution, or perhaps I'm missing something before I create an AudioStream object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions