(SOLVED) Texture only shows after ALT+TAB

I have this script that generates a texture wave form from an audioclip in audiosource.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;




public class wave : MonoBehaviour

{
[SerializeField] public AudioClip audio;

[SerializeField] public AudioClip CloneAudioClip;

[SerializeField] public Image waveform;
public Texture tex;


public void WaveTexture() {
   
    this.audio = GameObject.Find("Controller").GetComponent<AudioSource>().clip;
       
      
        AudioClip newAudioClip = AudioClip.Create(name, audio.samples, audio.channels, audio.frequency, false);
        float[] copyData = new float[audio.samples * audio.channels];
        audio.GetData(copyData, 0);
        List<float> monoData = new List<float>();
        for (int i = 0; i < copyData.Length; i+=2)
        {
            monoData.Add(copyData[i]);
        }
        newAudioClip.SetData(monoData.ToArray(), 0);
      

Texture2D PaintWaveformSpectrum(AudioClip audio, float saturation, int width, int height, Color col) {
     Texture2D tex = new Texture2D(width, height, TextureFormat.RGBA32, false);
     float[] samples = new float[audio.samples];
     float[] waveform = new float[width];
     audio.GetData(samples, 0);
     int packSize = ( audio.samples / width ) + 1;
     int s = 0;
     for (int i = 0; i < audio.samples; i += packSize) {
         waveform[s] = Mathf.Abs(samples[i]);
         s++;
     }
     for (int x = 0; x < width; x++) {
         for (int y = 0; y < height; y++) {
             tex.SetPixel(x, y, Color.black);
         }
     }
     for (int x = 0; x < waveform.Length; x++) {
         for (int y = 0; y <= waveform[x] * ((float)height * .75f); y++) {
             tex.SetPixel(x, ( height / 2 ) + y, col);
             tex.SetPixel(x, ( height / 2 ) - y, col);
         }
     }
    
     tex.Apply();
    
     return tex;
}






var color = new Color32(47, 157, 43, 255);

waveform.material.mainTexture = PaintWaveformSpectrum(newAudioClip,1, 5400,400,color);



}


}

The Audioclip is obtained from this script:

IEnumerator GetAudioClip()

    {

        var path = "file://" + SongData.fileName;
        // Start downloading
         using (var download = new WWW(path))
        {
           GameObject.Find("waveform").GetComponent<RectTransform>().localScale = new Vector2(0,0);
            // Wait for download to finish
            yield return download;
            // Create ogg vorbis file
            var clip = download.GetAudioClip();
            // Play it
            if (clip != null)
            {
               AudioClip song = clip;
               AudioSource.clip = song;

                Debug.Log ("File Loaded!");


            GameObject.Find("slider").GetComponent<Slider>().minValue = 0;
            GameObject.Find("slider").GetComponent<Slider>().maxValue = AudioSource.clip.length;
            GameObject.Find("waveform").GetComponent<RectTransform>().localScale = new Vector2(1,1);

            GameObject.Find("waveform").GetComponent<wave>().Invoke("WaveTexture", 1);

            }
            else     // Handle error
            {
                Debug.Log("Ogg vorbis download failed. (Incorrect link?)");

                AudioClip song = Resources.Load<AudioClip>("badliar");
                AudioSource.clip = song;


            GameObject.Find("slider").GetComponent<Slider>().minValue = 0;
            GameObject.Find("slider").GetComponent<Slider>().maxValue = AudioSource.clip.length;
            GameObject.Find("waveform").GetComponent<RectTransform>().localScale = new Vector2(1,1);


            }

        }

    }

Somehow the texture only apply when i hit ALT+TAB and return to the editor. In Built mode, it doesnt show at all.

Any suggestions?

Update:
When i put an imported audio (from assets) into the audiosource, this doesn’t happen.

I tried to invoke the waveTexture() function with 5 / 10 seconds delay to wait for the file to read, but it doesn’t work.
ALT+TAB immediately after the load or after works every-time…

Anyone can help me?

SOLVED!

Refreshing the image solved the problem:

/// . enable = false;
/// . enable = true;