Search Unity

Destroying object is not allowed at this time.

Discussion in 'Scripting' started by tfgrip, Aug 5, 2019.

  1. tfgrip

    tfgrip

    Joined:
    Oct 12, 2017
    Posts:
    22
    Hello,

    I am trying to destroy RenderTexture, but I'm getting an

    > Destroying object "Ceto Wave Spectrum GPU Buffer" is not allowed at this time.

    Any idea what does it mean? When is it "not allowed time"?

    Thank you
     
  2. Deleted User

    Deleted User

    Guest

  3. tfgrip

    tfgrip

    Joined:
    Oct 12, 2017
    Posts:
    22
    It's literally just the destruction of RenderTextures

    Code (csharp):
    1.  
    2. texList[i].Release();
    3. UnityEngine.Object.Destroy(texList[i]);
    4.  
    where texList is list of RenderTextures. I'm not sure what more context to give you, as the error is not saying much and I have no idea what can it even be caused by.

    It does not matter when is it destroyed (Update, OnDisable, OnDestroy). If you can tell me when can this error fire, I will be able to check it on my side.
     
  4. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Hmmm I don't think I've ever needed to call Object.Destroy(...) on a RenderTexture. I figured renderTexture.Release() was enough, but do correct me if I'm wrong.
     
  5. WhendricSo

    WhendricSo

    Joined:
    Jan 1, 2011
    Posts:
    171
    Did you try DestroyImmediate?
     
  6. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    270
    The RenderTexture as configured by that package may be different than other render textures. I'm not sure you should be manually destroying that. Did you talk to the package author about this?

    Also I'm not sure if you should be calling Destroy after Release. Both may defer releasing actual resources, so maybe what Destroy is telling you is that the texture is already scheduled to be released.
     
  7. tfgrip

    tfgrip

    Joined:
    Oct 12, 2017
    Posts:
    22
    DestroyImmediate had same effect.

    @doctorpangloss It's normal Unity's RenderTexture. I was thinking about Destroy as well, I can't see anywhere in the manual mentioned whether they should/can be destroyed or whether just releasing them is enough. This is a 3rd party code (CETO), so I believe they had a reason to do both. I sure hope so.
     
  8. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Hi @tfgrip . I"m having the same problem with CETO. Any news?
     
  9. tfgrip

    tfgrip

    Joined:
    Oct 12, 2017
    Posts:
    22
    None, we're just ignoring it and hoping for the best ¯\_(ツ)_/¯
     
    Joe-Censored likes this.
  10. dewey53

    dewey53

    Joined:
    Mar 24, 2020
    Posts:
    1
    I have the same situation,Occurs when debugging is turned off。
     
  11. canyon_gyh

    canyon_gyh

    Joined:
    Aug 15, 2018
    Posts:
    48
    i GameObject.DestroyImmediate RenderTexture)
    get this error
    Destroying object "TempBuffer 677 1920x1080" is not allowed at this time.
     
  12. canyon_gyh

    canyon_gyh

    Joined:
    Aug 15, 2018
    Posts:
    48
    I have solved this problem:
    Destroying object "TempBuffer 677 1920x1080" is not allowed at this time. when do Destory the RenderTexture by Object.DestroyImmediate or Object.Destroy;
    Here is the solution:
    1. Clear all references for RenderTexture
    2. RenderTexture.Release
    3. Object.DestroyImmediate(RenderTexture)

    I play movie to ugui view,use VideoPlayer , RenderTexture _rt, UnityEngine.UI.RawImage;
    so when i destory RenderTexture,
    first clear RawImage.texture and VideoPlayer.targetTexture
    second clear RenderTexture.active :
    if (RenderTexture.active == _rt)
    RenderTexture.active = null;
    finally
    Object.DestroyImmediate(_rt);

    Code (CSharp):
    1.  
    2. RenderTexture _rt = this.m_rtex;
    3. this.m_rtex = null;
    4.  
    5. if (null != this.m_vper)
    6.     this.m_vper.targetTexture = null;
    7. if (null != this.m_rawImg)
    8.     this.m_rawImg.texture = null;
    9.    
    10. if(null != _rt)
    11. {
    12.     if (RenderTexture.active == _rt)
    13.         RenderTexture.active = null;
    14.  
    15.     _rt.Release();
    16.     GameObject.DestroyImmediate(_rt);
    17. }
    18.  
     
  13. akilar1002

    akilar1002

    Joined:
    Jul 18, 2016
    Posts:
    70
    You need release m_enabledData reference.
    like this:

    var RTsElement = m_enabledData.GetEnumerator();
    while (RTsElement.MoveNext())
    {
    var RTs = RTsElement.Current;
    if (RTs == null)
    continue;
    for (int index = 0; index<RTs.Length; ++index)
    RTs[index] = null;
    }
    RTsElement.Dispose();
    m_enabledData.Clear();