Help!How to release these resource completely?

Started by
1 comment, last by L. Spiro 9 years, 12 months ago

Here is a class that load D2DBitmap and draw it.


class YHMSprite
{
public:
	YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources);
	//YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources, LPCWSTR fileName);
	//YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources, Platform::String^ fileName);
	~YHMSprite();
	void LoadResource(LPCWSTR fileName);
	void Draw(float scale, float x, float y);
	void Draw(float scaleX, float scaleY, float x, float y);
	void Draw(float scaleX, float scaleY, float x, float y, float opacity);
	D2D1_SIZE_F GetBitmapSize();
private:
	std::shared_ptr<DX::DeviceResources> mDeviceResources;
	bool mIsResourceLoaded;
	ID2D1DrawingStateBlock *mStateBlock;
	ID2D1Bitmap *mBitmap;
	D2D1_SIZE_F	mBitmapSize;
};

And I create these resource


YHMSprite::YHMSprite(const std::shared_ptr<DX::DeviceResources>& deviceResources)
{
	mIsResourceLoaded = false;
	mDeviceResources = deviceResources;
	mDeviceResources->GetD2DFactory()->CreateDrawingStateBlock(&mStateBlock);
}

void YHMSprite::LoadResource(LPCWSTR fileName)
{
	ComPtr<IWICBitmapDecoder> wicBitmapDecoder;
	mDeviceResources->GetWicImagingFactory()->CreateDecoderFromFilename(fileName, nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &wicBitmapDecoder);
	ComPtr<IWICBitmapFrameDecode> wicBitmapFrame;
	wicBitmapDecoder->GetFrame(0, &wicBitmapFrame);
	ComPtr<IWICFormatConverter> wicFormatConverter;
	mDeviceResources->GetWicImagingFactory()->CreateFormatConverter(&wicFormatConverter);
	wicFormatConverter->Initialize(wicBitmapFrame.Get(), GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, nullptr, 0.0, WICBitmapPaletteTypeCustom);
	double DpiX = 72.0f, DpiY = 72.0f;
	wicFormatConverter->GetResolution(&DpiX, &DpiY);
	mDeviceResources->GetD2DDeviceContext()->CreateBitmapFromWicBitmap(wicFormatConverter.Get(), BitmapProperties(PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED), static_cast<float>(DpiX), static_cast<float>(DpiY)), &mBitmap);
	mBitmapSize = mBitmap->GetSize();
	mIsResourceLoaded = true;
}

In my code, I release these resource using this destruction function

YHMSprite::~YHMSprite()

{
mBitmap->Release();
mStateBlock->Release();
}
I release my resource like this:
YHMSprite* test = new YHMSprite(....);
delete test;
But it doesn't release test completed!
Thanks.
My english is very poor!
Advertisement

after delete test set it to null. So...

delete test;

test = null;

But it doesn't release test completed!

How are you verifying this?
I am leaving in 30 seconds so I can’t go over the rest of your code for leaks, but right now the big question is how do you know they are not being released?


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement