Need some help - SOLVED
Need some help - SOLVED
Hi everyone!
So I was coding "drawing bitmaps with Direct2D" from MSDN tutorials. Everything works fine, Initialization succedes, the bitmap draws , BUT the program throws an exception when I close it. It crashes when I am trying to release the bitmap ( m_bitmap->Release(); )
Its the first time i got this kind of probplem - crashing when releasing objects/resources ...
Could you help me?
So I was coding "drawing bitmaps with Direct2D" from MSDN tutorials. Everything works fine, Initialization succedes, the bitmap draws , BUT the program throws an exception when I close it. It crashes when I am trying to release the bitmap ( m_bitmap->Release(); )
Its the first time i got this kind of probplem - crashing when releasing objects/resources ...
Could you help me?
Last edited by SunShine on August 28th, 2013, 5:32 pm, edited 1 time in total.
Re: Need some HELP
having some code to look at would help ._. (also seems you accidently posted 2 threads )
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Need some HELP
Deleted the duplicate....
But yea, I get that sometimes too. Cannot remember what it was then, but I think it was because the object I'm trying to release was already released. So if you release an already released object it will crash. If you use ComPtr object it should release itself when it goes out of the scope.
But yea, I get that sometimes too. Cannot remember what it was then, but I think it was because the object I'm trying to release was already released. So if you release an already released object it will crash. If you use ComPtr object it should release itself when it goes out of the scope.
ʕ •ᴥ•ʔ
Re: Need some HELP
Hi all.
The code is prety much the same as from MSDN, but here:
Theres really all in to it, if you want to see the MSDN thread:
http://msdn.microsoft.com/en-us/library ... s.85).aspx
The code is prety much the same as from MSDN, but here:
Code: Select all
bool BitmapClass::Initialize( LPCWSTR filename, ID2D1HwndRenderTarget* renderTarget )
{
// NOTE: my bitmap is declared as ID2D1Bitmap* in the header
IWICImagingFactory* factory;
IWICBitmapDecoder* decoder;
IWICBitmapFrameDecode* source;
IWICFormatConverter* converter;
HRESULT result;
// --- WIC FACTORY --- //
result = CoCreateInstance( CLSID_WICImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IWICImagingFactory, (LPVOID*)&factory );
if( FAILED( result ) )
return false;
// --- BITMAP DECODER --- //
result = factory->CreateDecoderFromFilename( filename, NULL, GENERIC_READ, WICDecodeMetadataCacheOnLoad, &decoder );
if( FAILED( result ) )
return false;
result = decoder->GetFrame( 0, &source );
if( FAILED( result ) )
return false;
// --- CONVERTER --- //
result = factory->CreateFormatConverter( &converter );
if( FAILED( result ) )
return false;
// Convert Bitmap pixel format
result = converter->Initialize( source, GUID_WICPixelFormat32bppPBGRA, WICBitmapDitherTypeNone, NULL, 0.f, WICBitmapPaletteTypeMedianCut );
if( FAILED( result ) )
return false;
// Create ID2D1Bitmap
result = renderTarget->CreateBitmapFromWicBitmap( converter, NULL, &m_bitmap );
if( FAILED( result ) )
return false;
factory->Release();
factory = NULL;
converter->Release();
converter = NULL;
source->Release();
source = NULL;
decoder->Release();
decoder = NULL;
return true;
}
void BitmapClass::Shutdown()
{
if( m_bitmap )
{
m_bitmap->Release(); // <<<<< CRASHES RIGHT HERE <<<<<<
m_bitmap = NULL;
}
return;
}
http://msdn.microsoft.com/en-us/library ... s.85).aspx
Re: Need some HELP
have you probably not initialize m_bitmap to null? probably the loading fails and since m_bitmap is not a valid pointer (but has an arbitrary value) it would fail o.o
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Need some HELP
Hi LuisR14.
I'm not exactly sure what you mean by that, but as I said beffore, the initialization succedes( the bitmap loads and i can draw it ). The only problem is when I try to release the bitmap( when i close the program )
I'm not exactly sure what you mean by that, but as I said beffore, the initialization succedes( the bitmap loads and i can draw it ). The only problem is when I try to release the bitmap( when i close the program )
Re: Need some HELP
oh ok, then probably is what Lux said
always available, always on, about ~10 years c/c++, java[script], win32/directx api, [x]html/css/php/some asp/sql experience. (all self taught)
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Knows English, Spanish and Japanese.
[url=irc://irc.freenode.net/#pchili]irc://irc.freenode.net/#pchili[/url] [url=irc://luisr14.no-ip.org/#pchili]alt[/url] -- join up if ever want real-time help or to just chat --
Re: Need some HELP
Try to check if the pointer is not null before the release, like this:
Code: Select all
if(m_bitmap)
{
m_bitmap->Release();
}
Re: Need some HELP
Hi clau007.
I did check, I allways do. ( see the code i wrote down, I think you missed that part )
This is some kind of black magic
I hope someone knows the solution and will help
I did check, I allways do. ( see the code i wrote down, I think you missed that part )
This is some kind of black magic
I hope someone knows the solution and will help
Re: Need some HELP
Clean and zip your solution and post it here. Someone will run a debug on it and point you in the right direction.
Chili