I can create objects for an context using the factory methods like this:
RenderTarget->CreateSolidColorBrush().
Is there a way to release such a brush? I am trying to avoid a
destroy/creation cycle of my render target, so I rebind it via BindDC() on
every WM_PAINT message.
But if I ->Release() such objects like the brush or savestates etc., the
next BindDC() call (actually, the BeginDraw() call) causes a crash.
How can I release such objects created by the RenderTarget Factory functions?
thanks
doc
I managed world, you can release unmanaged resources by
IDisposable.Dispose() method implemented in DirectUnknown base member
class. (See WindowsAPI code pack documentation)
In managed C++ world, you can write your own wrapper for the unmanaged
pointer, just implementing public destructor in managed class ref
Interface
Interface::Interface( System::IntPtr^ com )
{
_pointer = reinterpret_cast<IUnknown*>(com->ToPointer());
}
Interface::~Interface()
{
if (_pointer != nullptr)
{
_pointer->Release();
_pointer = nullptr;
}
}
IntPtr^ Interface::Object::get()
{
return IntPtr ( _pointer );
}
In unmanaged world, call COM interface IUnknown->Release() method
Here is an example that shows how to create and release a solid green brush.
Hope it helps.
To create a solid green brush:
ID2D1SolidColorBrush *m_pGreenBrush;
ID2D1HwndRenderTarget *m_pRenderTarget;
...
HRESULT hr = m_pRenderTarget->CreateSolidColorBrush(
D2D1::ColorF(D2D1::ColorF(D2D1::ColorF::Green, 1.0f)),
&m_pGreenBrush
);
...
To release the brush:
if(m_pGreenBrush != NULL)
{
m_pGreenBrush->Release();
m_pGreenBrush = NULL;
}
For more information on how to use brushes, see Brushes Overview at
http://msdn.microsoft.com/en-us/library/dd756651(VS.85).aspx.
Happy coding. :)
"happy coding" wrote:
> Hi,
>
> Here is an example that shows how to create and release a solid green brush.
> Hope it helps.
> ....
> if(m_pGreenBrush != NULL)
> {
> m_pGreenBrush->Release();
> m_pGreenBrush = NULL;
> }
>
I know that, but actually, it does not work correctly if you Rebind() an DC.
Please
read what I have posted:
> > Is there a way to release such a brush? I am trying to avoid a
> > destroy/creation cycle of my render target, so I rebind it via BindDC() on
> > every WM_PAINT message.
> >
> > But if I ->Release() such objects like the brush or savestates etc., the
> > next BindDC() call (actually, the BeginDraw() call) causes a crash.
> >
> > How can I release such objects created by the RenderTarget Factory functions?
when the RenderTarget is not being released, but re used?
thanks
doc