Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

repost: how to release objects in D2D1

11 views
Skip to first unread message

docschnipp

unread,
Dec 4, 2009, 5:46:01 PM12/4/09
to
Hi,

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

hack2root

unread,
Dec 16, 2009, 10:38:29 PM12/16/09
to

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

coding@discussions.microsoft.com happy coding

unread,
Jan 6, 2010, 4:23:03 PM1/6/10
to
Hi,

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. :)

docschnipp

unread,
Feb 4, 2010, 3:10:01 AM2/4/10
to

Hi "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

0 new messages