UpdateSurface and Access Violation

Started by
17 comments, last by Buckeye 14 years, 8 months ago
thanks for the answers, i changed it to C:/mcgiver.bmp, (after having moved the file there :P) but it doesnt work, i really cant figure out the problem..sorry i'm still a beginner

I love to learn new stuff about computer graphics and the DirectX APIs.

 

Advertisement
still no solutions.....i checked the content of the Info object and it's ok, it keeps all the informations about my mcgiver.bmp, so the path is correct, but i have problems with this CreateOffscreenPlainSurface function, the object &Surface is still NULL, but everything seems ready to work!....:(

I love to learn new stuff about computer graphics and the DirectX APIs.

 

YEAH :D.....i "solved" it....i tried with different pictures..that mcgiver.bmp is the problem...i tried with some .jpg pics and it works fine, but no one of my .bmp files can be loaded....they all give me back a

Direct3D9: (ERROR) :This format is not supported for offscreen plain surfaces. CreateOffscreenPlainSurface fails.

i cant understand why, isnt it the right way of loading bmp files?

(anyway even a 1600x1200 jpg file cant be loaded, with error
Direct3D9: (ERROR) :pRect doesn't fit inside the surface , i think it's too big no?)

thanks :)

I love to learn new stuff about computer graphics and the DirectX APIs.

 

Quote:Original post by Evil Steve
This:
if( D3DXGetImageInfoFromFile(path, &Info)!= D3D_OK )
Should be:
if(FAILED(D3DXGetImageInfoFromFile(path, &Info)))
Since there's 2 billion possible success codes, not just D3D_OK. For the actual problem, that function failing is usually caused by the path being invalid - again, the debug runtimes (Specifically d3dx9d.lib) will tell you exactly what the error is.


The documentation specifically says that it will return D3D_OK on success, why in the world would you consider this to be incorrect?
Quote:Original post by marius1930
The documentation specifically says that it will return D3D_OK on success, why in the world would you consider this to be incorrect?
Because all HRESULT values contain 2 billion possible success codes and 2 billion possible failure codes, with the top bit being set to indicate failure.
Just because the documentation says it will return D3D_OK doesn't mean that it'll always return that in future - for instance, in a future SDK version it may return S_FALSE (Which is still success, but not D3D_OK) to indicate that the image was loaded, just in a different format.

Quote:Original post by rekotc
Direct3D9: (ERROR) :This format is not supported for offscreen plain surfaces. CreateOffscreenPlainSurface fails.

i cant understand why, isnt it the right way of loading bmp files?
BMP files are almost always 24-bit, and I bet your card doesn't support 24-bit textures (Usually only 32-bit or 16-bit are supported). The options are:
1. Save the BMP as a 32-bit BMP (Some image editing software allows this).
2. Force the format to D3DFMT_X8R8G8B8 (Assuming D3DXLoadSurfaceFromFile can convert, I'm not entirely sure on this).
Also, for reference - it's usually preferable to load the image as a texture (Using D3DXCreateTextureFromFileEx), and then render it as a textured quad (Which will also let you do alpha blending, rotation, and so on) - although one thing at a time [smile].

Quote:Original post by marius1930
(anyway even a 1600x1200 jpg file cant be loaded, with error
Direct3D9: (ERROR) :pRect doesn't fit inside the surface , i think it's too big no?)
The documentation for UpdateSurface states: "No stretching or shrinking is allowed (the rects must be the same size)" - I assume that means you can't update a surface using source surface that is larger than the dest surface in that case.
ok thank you very much :), just the last question, i still dont understand when you say "you can't update a surface using source surface that is larger than the dest surface in that case", i created a new Surface and i allocated enough memory for that file using the Info object to know about the image size and color depth, so i thought the Surface object was big enough for that jpg, then i simply called UpdateSurface to copy the Surface to the BackBuffer. I cant understand what is wrong (i'm simply trying to follow a book about direct3d :))

I love to learn new stuff about computer graphics and the DirectX APIs.

 

As Evil Steve said, it appears that UpdateSurface requires that both buffer RECTs be the same size. If the backbuffer isn't exactly the same size as the loaded image, you get an error return. You're specifying NULL for the rect sizes, so it defaults to the full size of each buffer.

Try setting the RECT parameters in the buffer call.

If the source is smaller than the destination, use the size of the source buffer for both RECT parameters.

If the destination is smaller then the source, use the size of the destination buffer.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Quote:Original post by Buckeye
Try setting the RECT parameters in the buffer call.

mmm.....i cant understand how to do it, i understood that i have to set the size of source and destination, but i cant find out how

I love to learn new stuff about computer graphics and the DirectX APIs.

 

I've never done it but the documentation seems clear enough. You too can try looking at the SDK docs!
HRESULT IDirect3DDevice9::UpdateSurface(  IDirect3DSurface9* pSourceSurface,  CONST RECT* pSourceRect,  IDirect3DSurface9* pDestinationSurface,  CONST POINT* pDestinationPoint);

Instead of setting pSourceRect and pDestinationPoint to NULL (which you do), create a CONST RECT sized to be as small as or smaller than the source and destination sizes. You can get the sizes of the surfaces with
HRESULT IDirect3DSurface9::GetDesc(  D3DSURFACE_DESC * pDesc);

The D3DSURFACE_DESC has the width and height of the surface. Use the smaller of the 2 widths and the smaller of the 2 heights. One may be from the source and one from the destination, or both width and height from just one of the two. Use those smaller values to set the RECT values.

You also need to create a CONST POINT of (0,0) for the 4th parameter.

You may see just a part of the texture filling the destination, the whole texture filling just a part of the destination, or part of the texture filling part of the destination. The entire texture will only fill the background if the texture is exactly the right size.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement