Jump to content
  • Advertisement
Sign in to follow this  

Help!How to release these resource completely?

This topic is 2011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is a class that load D2DBitmap and draw it.

class YHMSprite
	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);
	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();
	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;

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;
	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


I release my resource like this:
YHMSprite* test = new YHMSprite(....);
delete test;
But it doesn't release test completed!

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!