locked
Show an image and get av exception

    Question

  • I wrote code to show an image but get the av exception

    Unhandled exception at 0x0137CCC4 in Direct2DApp1.exe: 0xC0000005: Access violation reading location 0x00000000.

    the piece of code is here and what's wrong?

    	DX::ThrowIfFailed(m_wicFactory->CreateDecoderFromFilename(L"0.jpg", nullptr, GENERIC_READ, WICDecodeMetadataCacheOnDemand, &decoder));
    	DX::ThrowIfFailed(decoder->GetFrame(0, &frame));
    	DX::ThrowIfFailed(m_wicFactory->CreateFormatConverter(&converter));
    	DX::ThrowIfFailed(
    		converter->Initialize(
    			frame.Get(), 
    			GUID_WICPixelFormat32bppPBGRA, 
    			WICBitmapDitherTypeNone,
    			nullptr,
    			0.0,
    			WICBitmapPaletteTypeCustom
    			)
    		);
    
    	double dpiX = 96.0f;
    	double dpiY = 96.0f;
    
    	DX::ThrowIfFailed(
    		converter->GetResolution(&dpiX, &dpiY)
    		);
    
    	uint32 width = 0;
    	uint32 height = 0;
    
    	converter->GetSize(&width, &height);
    
    	DX::ThrowIfFailed(
    		m_d2dContext->CreateBitmapFromWicBitmap(
    			converter.Get(),
                BitmapProperties(
    			PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE),
                    static_cast<float>(dpiX),
                    static_cast<float>(dpiY)
                    ),
    			&m_bitmap
    			)
    		); // AV Exception this line

    Sunday, November 11, 2012 4:07 AM

Answers

  • Hi,

    Please check these points:

     1. Make sure the 0.jpg is in the same folder in the Direct2DApp1.exe.
     2. Make sure if the m_d2dContext is not null, you should call it after CreateDeviceResources function.
     
     
    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Billy Du Monday, November 12, 2012 4:49 PM
    Monday, November 12, 2012 5:53 AM
    Moderator