mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
2k stars 262 forks source link

Image with soft mask will occur error in IEnumerator process #182

Closed chiangandy closed 1 month ago

chiangandy commented 1 month ago

I have project using the soft mask and get error in process, error code response error occur in soft mask. I cannot find the reason. my situation is ...

  1. image set up soft mask in prefab
  2. image prefab run task in IEnumerator process
  3. process change sprite in image.
  4. process got error after yield return request.SendWebRequest(); .

can some one help me to check this...

error screen,

截圖 2024-08-07 上午10 03 53

mask image

截圖 2024-08-07 上午10 08 18

process code is ... ` IEnumerator update_post_message_view() // activity_check_in womo_activity_check_in, int activity_id, int kol_id {

    ClearContent(post_contentContainer);
    // List<post_message> womo_post_message_list = womo_activity_check_in.get_post_message_list(activity_id, kol_id);
    int item_count = 0;
    foreach (post_message womo_post_message in womo_post_message_list)
    {
        Debug.Log("checkpoint 1------");
        var _ItemPrefab =  Instantiate(Post_item_Prefab);
        var _ItemPrefab_set = _ItemPrefab.GetComponent<post_content_item_process>();

        //如果有設定reply_post_id 代表是回復訊息,啟動reply面板
        if (womo_post_message.reply_post_id != 0)
        {
            _ItemPrefab =  Instantiate(Post_item_reply_Prefab);
            _ItemPrefab_set = _ItemPrefab.GetComponent<post_content_item_process>();
        }

        _ItemPrefab_set.reply_btn.onClick.AddListener(() => OnreplyButtonClick(womo_post_message));
        _ItemPrefab_set.del_btn.onClick.AddListener(() => OndelButtonClick(womo_post_message));
        // 下載圖像並貼入po文
        UnityWebRequest request = UnityWebRequestTexture.GetTexture(womo_post_message.user_profile_image_url);
        Debug.Log("checkpoint 2------");
        yield return request.SendWebRequest();
        Debug.Log("checkpoint 3------1");
        if (request.result != UnityWebRequest.Result.Success)
        {
            Debug.LogError("Image download failed: " + request.error);
        }
        else
        {
            Texture2D texture = DownloadHandlerTexture.GetContent(request);
            Sprite profile_image_sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            _ItemPrefab_set.update_content(profile_image_sprite, womo_post_message.user_name+" "+womo_post_message.create_date, womo_post_message.content);
            _ItemPrefab.transform.SetParent(post_contentContainer, false);
            item_count += 1;
        }

    }
    post_contentContainer.sizeDelta = new Vector2(post_contentContainer.sizeDelta.x, item_count*120);
}`

error message NullReferenceException: Object reference not set to an instance of an object Coffee.UISoftMaskInternal.FrameCache.TryGet[T] (System.Object key1, System.String key2, T& result) (at Library/PackageCache/com.coffee.softmask-for-ugui@9370fd2fb7/Runtime/Internal/Utilities/FrameCache.cs:30) Coffee.UISoftMaskInternal.CanvasExtensions.IsStereoCanvas (UnityEngine.Canvas canvas) (at Library/PackageCache/com.coffee.softmask-for-ugui@9370fd2fb7/Runtime/Internal/Extensions/CanvasExtensions.cs:44) Coffee.UISoftMask.SoftMaskable.UnityEngine.UI.IMaterialModifier.GetModifiedMaterial (UnityEngine.Material baseMaterial) (at Library/PackageCache/com.coffee.softmask-for-ugui@9370fd2fb7/Runtime/SoftMaskable.cs:138) UnityEngine.UI.Graphic.get_materialForRendering () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Graphic.cs:514) UnityEngine.UI.Graphic.UpdateMaterial () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Graphic.cs:675) UnityEngine.UI.Image.UpdateMaterial () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Image.cs:914) UnityEngine.UI.Graphic.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Graphic.cs:653) UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/CanvasUpdateRegistry.cs:215) UnityEngine.UI.ScrollRect:LateUpdate() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/ScrollRect.cs:834)

chiangandy commented 1 month ago

Everybody can help me? let me provide more information. unity version 2021.3.30f1 LTS mac M2 pro CPU

when I use original build it mask component it can run without any error, but when I change to use soft mask, error is appear. I even want to change to use async ti avoid this, but webrequest only can use IEnumerator. So sad. :(

Any information will be appreciated.

Andy

mob-sakai commented 1 month ago

Thank you for your reporting! I would like to know more about this issue. Tell me about your develop/build environment.

Could you please attach a minimal project (included Assets, Packages and ProjectSettings directories) that reproduces the issue?

repos

mob-sakai commented 1 month ago

Tips:

var _ItemPrefab =  Instantiate(Post_item_Prefab, post_contentContainer, false);
_ItemPrefab.SetActive(false);

...

if (request.result != UnityWebRequest.Result.Success)
{
    Destroy(_ItemPrefab);
    Debug.LogError("Image download failed: " + request.error);
}
else
{
    Texture2D texture = DownloadHandlerTexture.GetContent(request);
    Sprite profile_image_sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
    _ItemPrefab_set.update_content(profile_image_sprite, womo_post_message.user_name+" "+womo_post_message.create_date, womo_post_message.content);
    _ItemPrefab.SetActive(true);
    item_count += 1;
}
mob-sakai commented 1 month ago

Yeah, well, even if there is no Canvas in the parents of the prefab instance, there should not be an error. I will fix it.

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 2.2.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

chiangandy commented 1 month ago

Dear mon-sakai,

Thanks for your quick update, it is solve my issue.... Thanks a lot :)

Andy 江謝迪

mob-sakai @.***> 於 2024年8月11日 週日 上午8:50寫道:

Closed #182 https://github.com/mob-sakai/SoftMaskForUGUI/issues/182 as completed.

— Reply to this email directly, view it on GitHub https://github.com/mob-sakai/SoftMaskForUGUI/issues/182#event-13830457016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALGOG5FHVNY3FG4LXF7JV3ZQ2YM5AVCNFSM6AAAAABMDOB4A6VHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJTHAZTANBVG4YDCNQ . You are receiving this because you authored the thread.Message ID: @.***>

github-actions[bot] commented 1 week ago

:tada: This issue has been resolved in version 3.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: