Archived

This topic is now archived and is closed to further replies.

ms291052

Loading A Bitmap To A Surface

Recommended Posts

I have this code to load a .bmp file onto a d3d surface but I can''t seem to find the rather massive memory leak in it. I''ve noticed that if I comment out the CreateOffscreen Plane it throws a NullReferenceException but I don''t get it! Here''s my code: int LoadBitmapToSurface(char* PathName, LPDIRECT3DSURFACE9* ppSurface, LPDIRECT3DDEVICE9 pDevice) { HRESULT r; HBITMAP hBitmap; BITMAP Bitmap; hBitmap = (HBITMAP)LoadImage(NULL, PathName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); if(hBitmap == NULL) return E_FAIL; GetObject(hBitmap, sizeof(BITMAP), &Bitmap); DeleteObject(hBitmap); //r = pDevice->CreateImageSurface(Bitmap.bmWidth,Bitmap.bmHeight, D3DFMT_X8R8G8B8, ppSurface); r = pDevice->CreateOffscreenPlainSurface(Bitmap.bmWidth, Bitmap.bmHeight, D3DFMT_X8R8G8B8, D3DPOOL_SCRATCH, ppSurface, NULL); if(FAILED(r)) return E_FAIL; r = D3DXLoadSurfaceFromFile(*ppSurface, NULL, NULL, PathName, NULL, D3DX_FILTER_NONE, 0, NULL); if(FAILED(r)) return E_FAIL; return S_OK; }

Share this post


Link to post
Share on other sites