summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorJonathan Yap <none@none>2011-12-02 09:22:27 -0500
committerJonathan Yap <none@none>2011-12-02 09:22:27 -0500
commit7226b23366805ae259000df25a622fc98a722d14 (patch)
treecfaa4453aa67a4f81cd29a922a403c1b05144446 /indra/newview
parenta4cb08ae5d20416e21bbc70540527097495af887 (diff)
STORM-591 Made mininum fade time 0.01 seconds to prevent divide by zero and negative fade times.
Rewrote two blocks of code to eliminate early returns.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llpanelnearbymedia.cpp20
-rw-r--r--indra/newview/llvieweraudio.cpp50
2 files changed, 45 insertions, 25 deletions
diff --git a/indra/newview/llpanelnearbymedia.cpp b/indra/newview/llpanelnearbymedia.cpp
index 53fc64f089..c01adc3c35 100644
--- a/indra/newview/llpanelnearbymedia.cpp
+++ b/indra/newview/llpanelnearbymedia.cpp
@@ -808,14 +808,26 @@ bool LLPanelNearByMedia::setDisabled(const LLUUID &row_id, bool disabled)
{
if (row_id == PARCEL_AUDIO_LIST_ITEM_UUID)
{
- if (disabled) onClickParcelAudioStop();
- else onClickParcelAudioPlay();
+ if (disabled)
+ {
+ onClickParcelAudioStop();
+ }
+ else
+ {
+ onClickParcelAudioPlay();
+ }
return true;
}
else if (row_id == PARCEL_MEDIA_LIST_ITEM_UUID)
{
- if (disabled) onClickDisableParcelMedia();
- else onClickEnableParcelMedia();
+ if (disabled)
+ {
+ onClickDisableParcelMedia();
+ }
+ else
+ {
+ onClickEnableParcelMedia();
+ }
return true;
}
else {
diff --git a/indra/newview/llvieweraudio.cpp b/indra/newview/llvieweraudio.cpp
index 1e5c742cf9..f01fe174a4 100644
--- a/indra/newview/llvieweraudio.cpp
+++ b/indra/newview/llvieweraudio.cpp
@@ -74,11 +74,13 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI)
// Record the URI we are going to be switching to
mNextStreamURI = streamURI;
- if (mFadeState == FADE_IDLE)
+ switch (mFadeState)
{
+ case FADE_IDLE:
// If a stream is playing fade it out first
if (!gAudiop->getInternetStreamURL().empty())
{
+ // The order of these tests is important, state FADE_OUT will be processed below
mFadeState = FADE_OUT;
}
// Otherwise the new stream can be faded in
@@ -88,21 +90,21 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI)
gAudiop->startInternetStream(mNextStreamURI);
startFading();
registerIdleListener();
- return;
+ break;
}
- }
- if (mFadeState == FADE_OUT)
- {
- startFading();
- registerIdleListener();
- return;
- }
+ case FADE_OUT:
+ startFading();
+ registerIdleListener();
+ break;
- if (mFadeState == FADE_IN)
- {
- registerIdleListener();
- return;
+ case FADE_IN:
+ registerIdleListener();
+ break;
+
+ default:
+ llwarns << "Unknown fading state: " << mFadeState << llendl;
+ break;
}
}
@@ -112,13 +114,15 @@ void LLViewerAudio::startInternetStreamWithAutoFade(std::string streamURI)
// A return of true means we have finished with it and the callback will be deleted.
bool LLViewerAudio::onIdleUpdate()
{
+ bool fadeIsFinished = false;
+
if (mDone)
{
// This should be a rare or never occurring state.
if (mFadeState == FADE_IDLE)
{
deregisterIdleListener();
- return true; // Stop calling onIdleUpdate
+ fadeIsFinished = true; // Stop calling onIdleUpdate
}
// we have finished the current fade operation
@@ -133,13 +137,12 @@ bool LLViewerAudio::onIdleUpdate()
mFadeState = FADE_IN;
gAudiop->startInternetStream(mNextStreamURI);
startFading();
- return false;
}
else
{
mFadeState = FADE_IDLE;
deregisterIdleListener();
- return true; // Stop calling onIdleUpdate
+ fadeIsFinished = true; // Stop calling onIdleUpdate
}
}
else if (mFadeState == FADE_IN)
@@ -148,18 +151,17 @@ bool LLViewerAudio::onIdleUpdate()
{
mFadeState = FADE_OUT;
startFading();
- return false;
}
else
{
mFadeState = FADE_IDLE;
deregisterIdleListener();
- return true; // Stop calling onIdleUpdate
+ fadeIsFinished = true; // Stop calling onIdleUpdate
}
}
}
- return false;
+ return fadeIsFinished;
}
void LLViewerAudio::stopInternetStreamWithAutoFade()
@@ -174,8 +176,10 @@ void LLViewerAudio::stopInternetStreamWithAutoFade()
void LLViewerAudio::startFading()
{
- const F32 AUDIO_MUSIC_FADE_IN_TIME = 3.0;
- const F32 AUDIO_MUSIC_FADE_OUT_TIME = 2.0;
+ const F32 AUDIO_MUSIC_FADE_IN_TIME = 3.0f;
+ const F32 AUDIO_MUSIC_FADE_OUT_TIME = 2.0f;
+ // This minimum fade time prevents divide by zero and negative times
+ const F32 AUDIO_MUSIC_MINIMUM_FADE_TIME = 0.01f;
if(mDone)
{
@@ -186,6 +190,10 @@ void LLViewerAudio::startFading()
{
mFadeTime = AUDIO_MUSIC_FADE_OUT_TIME;
}
+
+ // Prevent invalid fade time
+ mFadeTime = llmax(mFadeTime, AUDIO_MUSIC_MINIMUM_FADE_TIME);
+
stream_fade_timer.reset();
stream_fade_timer.setTimerExpirySec(mFadeTime);
mDone = false;