Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 6, 2009, 9:46:04 PM (15 years ago)
Author:
rgrieder
Message:

Audio sources seem to be very limited resources. If we create more than available sources (usually more than 256), it will not result in a failed assert anymore. Instead, the sound will simply not load and play.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation2/src/orxonox/sound/BaseSound.cc

    r6255 r6260  
    5555        {
    5656            alGenSources(1, &this->audioSource_);
    57             assert(this->audioSource_ != 0);
     57            if (!alIsSource(this->audioSource_))
     58                COUT(1) << "Sound: Source generation failed: " << SoundManager::getALErrorString(alGetError()) << std::endl;
    5859        }
    5960    }
     
    6263    {
    6364        this->setSource("");
    64         if (GameMode::playsSound())
     65        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    6566            alDeleteSources(1, &this->audioSource_);
    6667    }
     
    7778    {
    7879        this->state_ = Playing;
    79         if (GameMode::playsSound() && this->getSourceState() != AL_PLAYING)
     80        if (GameMode::playsSound() && alIsSource(this->audioSource_) && this->getSourceState() != AL_PLAYING)
    8081        {
    8182            alSourcePlay(this->audioSource_);
     
    8990    {
    9091        this->state_ = Stopped;
    91         if (GameMode::playsSound())
     92        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    9293            alSourceStop(this->audioSource_);
    9394    }
     
    9899            return;
    99100        this->state_ = Paused;
    100         if (GameMode::playsSound())
     101        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    101102            alSourcePause(this->audioSource_);
    102103    }
     
    104105    ALint BaseSound::getSourceState() const
    105106    {
    106         if (GameMode::playsSound())
     107        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    107108        {
    108109            ALint state;
     
    145146    {
    146147        this->bLoop_ = val;
    147         if (GameMode::playsSound())
     148        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    148149            alSourcei(this->audioSource_, AL_LOOPING, (val ? AL_TRUE : AL_FALSE));
    149150    }
     
    158159        }       
    159160        this->pitch_ = pitch;
    160         if (GameMode::playsSound())
     161        if (GameMode::playsSound() && alIsSource(this->audioSource_))
    161162        {
    162163            if (int error = alGetError())
     
    176177        if (this->soundBuffer_ != NULL)
    177178        {
    178             alSourceStop(this->audioSource_);
    179             // Unload old sound first
    180             alSourcei(this->audioSource_, AL_BUFFER, 0);
     179            if (alIsSource(this->audioSource_))
     180            {
     181                alSourceStop(this->audioSource_);
     182                // Unload old buffer first
     183                alSourcei(this->audioSource_, AL_BUFFER, 0);
     184            }
    181185            SoundManager::getInstance().releaseSoundBuffer(this->soundBuffer_, this->bPooling_);
    182186            this->soundBuffer_.reset();
     
    184188
    185189        this->source_ = source;
    186         if (source_.empty())
     190        if (source_.empty() || !alIsSource(this->audioSource_))
    187191            return;
    188192
     
    200204
    201205        alSourcei(this->audioSource_, AL_BUFFER, this->soundBuffer_->getBuffer());
    202         if (alGetError() != AL_NO_ERROR)
    203         {
    204             COUT(2) << "Sound: OpenAL: Error loading sample file: " << source << std::endl;
     206        if (ALuint error = alGetError())
     207        {
     208            COUT(1) << "Sound Error: Could not load file \"" << source << "\": " << SoundManager::getALErrorString << std::endl;
    205209            return;
    206210        }
Note: See TracChangeset for help on using the changeset viewer.