Texture2D and Sprite flicker when resizing — Bug?

Hello everybody.

I am using UGUI (the new Unity UI system) and trying to resize Texture2D. While resizing, the texture is not rendering at all! Unlike dragging which is working perfectly.

For rendering the Texture2D, I am using RawImage which I am also setting from my script. (NOT from Resources Folder! i.e. NOT using Resources.Load)

I tried using Image component instead and created a sprite form the incoming texture but ended up with the same result.

Here’s a demo video:

Here’s the resizing code:

public void myResizeBulk(float newWidth, float newHeight)
{
    gameObject.GetComponent<RectTransform>()
        .set_size(new Vector2(Mathf.Floor(m_Width + newWidth)
            , (Mathf.Floor(m_Height + newHeight))));

    Resize(Mathf.FloorToInt(m_Width + newWidth), Mathf.FloorToInt(m_Height + newHeight));

    if (gameObject.GetComponent<RawImage>())
        gameObject.GetComponent<RawImage>().SetNativeSize();
    else
        gameObject.GetComponent<Image>().SetNativeSize();
}

set_size is an extension method, here’s its code:

public static void set_size(this RectTransform trans, Vector2 new_size)
{
    Vector2 oldSize = trans.rect.size;
    Vector2 deltaSize = new_size - oldSize;
    trans.offsetMin = trans.offsetMin - new Vector2(deltaSize.x * trans.pivot.x, deltaSize.y * trans.pivot.y);
    trans.offsetMax = trans.offsetMax + new Vector2(deltaSize.x * (1f - trans.pivot.x), deltaSize.y * (1f - trans.pivot.y));
}

And finally Resize is a method which calls an external function to resize the actual texture (webpage) coming from the third-party C++ engine:

public void Resize(int _Width, int _Height)
{
    m_Width = _Width;
    m_Height = _Height;

    if (m_Texture == null)
    {
        m_Texture = new Texture2D(m_Width, m_Height, TextureFormat.RGBA32, false);
    }
    else
    {
        m_Texture.Resize(m_Width, m_Height, TextureFormat.RGBA32, false);
        m_Texture.Apply(false, false);
    }
    //m_Texture.filterMode = FilterMode.Point;

    if (m_WebView != null)
    {
        m_WebView.Resize(m_Width, m_Height);
        //Resize calls an external C++ function: awe_webview_resize(m_Instance, _Width, _Height);
    }
    else
    {
        m_WebView = AwesomiumUnityWebCore.CreateWebView(m_Width, m_Height);
    }
}

A second problem that I solved (might enlighten you those who are going to answer) is that sometimes when resizing for extensive amount of time I am getting an error: “Failed to create 2D texture” and “SUCCEEDED(hr)” Where the texture actually goes completely invisible. I solved this by calling the following method every 1 second:

        UnityEditor.EditorUtility.UnloadUnusedAssetsImmediate();
        //Resources.UnloadUnusedAssets(); //this one didn't do the trick!

Picture of the problem’s error log solved with Unloading Used Assets:

Oh my God! I cannot believe this! Merely manipulating SizeDelta of the rectTransform did the trick without flickering! Without going through the extension function, SetNativeSize, and setting the size in the C++ Engine!

Though I still have no idea why that flickering happened in the old method.

EDIT: Apparently changing SizeDelta from script has no changes! Also I cannot change width and height of the RectTransform from the inspector in runtime. Why is it working only with animation clips? O.o

2nd EDIT: Assigned runtime Animator controller to null when normalized time is <=1, apparently animator gets hold of the values and never lets go.