Skip to content

Commit

Permalink
Any public API that uses cached shader property IDs MUST initialize t…
Browse files Browse the repository at this point in the history
…hose IDs.

We can't know when these are called externally. In particular, they may be called before the AudioLink script has even been initialized, like in the Start method of a separate behavior. Initializing twice is a no-op, so there should be no perf issues here.
  • Loading branch information
pema99 committed Dec 12, 2023
1 parent 6ab46ea commit e8443fa
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Packages/com.llealloo.audiolink/Runtime/Scripts/AudioLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ private void OnDisable()

public void UpdateSettings()
{
InitIDs();
audioMaterial.SetFloat(_Gain, gain);
audioMaterial.SetFloat(_FadeLength, fadeLength);
audioMaterial.SetFloat(_FadeExpFalloff, fadeExpFalloff);
Expand All @@ -611,6 +612,7 @@ public void UpdateSettings()
// rather than bundled in with the other things in UpdateSettings().
public void UpdateThemeColors()
{
InitIDs();
audioMaterial.SetInt(_ThemeColorMode, themeColorMode);
audioMaterial.SetColor(_CustomThemeColor0, customThemeColor0);
audioMaterial.SetColor(_CustomThemeColor1, customThemeColor1);
Expand Down Expand Up @@ -689,6 +691,7 @@ public override void OnDeserialization()

private void UpdateGlobalString(int nameID, string input)
{
InitIDs();
const int maxLength = 32;
if (input.Length > maxLength)
input = input.Substring(0, maxLength);
Expand Down Expand Up @@ -755,6 +758,7 @@ public void DisableReadback()

public void SendAudioOutputData()
{
InitIDs();
audioSource.GetOutputData(_audioFramesL, 0); // left channel

if (_rightChannelTestCounter > 0)
Expand Down

0 comments on commit e8443fa

Please sign in to comment.