RonenNess / GeonBit.UI

UI system for MonoGame projects.
MIT License
478 stars 64 forks source link

Dispose RenderTarget2D #50

Closed bytecode-nu closed 6 years ago

bytecode-nu commented 6 years ago

RenderTarget2D allocates unmanaged resources (GPU memory) and thus Dispose() must be called at appropriate an time. I can find at least two classes that uses RenderTarget2D: UserInterface and Panel. I suggest that these two classes implement IDisposable so that the user can free/dispose the unmanaged resources.

I create multiple UserInterface instances and currently I do x.RenderTarget?.Dispose(), however, the RenderTarget2D of the Panel is protected and there is no getter for it.

Furthermore, there are at least two cases where _renderTarget is set to null without first calling Dispose().

UserInterface.cs:141:

set { _useRenderTarget = value; _renderTarget = null; }

Panel.cs:163:

if (_overflowMode == PanelOverflowBehavior.Overflow)
{
    _renderTarget = null;
    return;
}
RonenNess commented 6 years ago

You are right, fixed it (in dev).

Thank you for the report :)