Sign in to follow this  
m4ster

Problem with Surfaces SOLVED

Recommended Posts

Hi, I've tried to make a mini-game with DirectDraw, but there's a error with my game surfaces. Look at the code, before the call to CreateVideoSurface() the surface is 0, at the end of CreateVideoSurface() the surface is anything but not 0, and after the call to this function the surface again is zero. Here is the code: ================= ///////////////// // objects.cpp // ///////////////// LPDIRECTDRAWSURFACE7 g_lpDDSBackground; // Global variable int InitObjects() { ... // Hintergrund Image laden if(CreateVideoSurface(g_lpDDSBackground, 400, 300)) return(1); // -----------------> Here the Surface is 0 <----------------- ... } /////////////// // ddraw.cpp // /////////////// int CreateVideoSurface(LPDIRECTDRAWSURFACE7 lpDDSurface, int nWidth, int nHeight) { DDSURFACEDESC2 ddsd; A2PINITDDSTRUCT(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; ddsd.dwWidth = nWidth; ddsd.dwHeight = nHeight; if(FAILED(g_lpDD->CreateSurface(&ddsd, &lpDDSurface, NULL))) return(1); // ----------------->Here the Surface is anything but not 0<----------------- // success return(0); } ================= Thanks for Help [Edited by - m4ster on June 14, 2006 12:48:24 PM]

Share this post


Link to post
Share on other sites
You're passing LPDIRECTDRAWSURFACE7 by value so the CreateVideoSurface() function won't modify g_lpDDSBackground at all...


Try:


// Hintergrund Image laden
if(CreateVideoSurface(&g_lpDDSBackground, 400, 300))

...

int CreateVideoSurface(LPDIRECTDRAWSURFACE7* lppDDSurface, int nWidth, int nHeight)
{
...
if(FAILED(g_lpDD->CreateSurface(&ddsd, lppDDSurface, NULL)))


[note the & is gone from lppDDSurface passed to CreateSurface()]



There are other cleaner/nicer ways to return things from functions and to avoid excessive pointer use - but this is the DirectX forum [smile], you'll find plenty of discussions about coding style in the General Programming and Software Engineering forums.

Share this post


Link to post
Share on other sites
hi, I did what u said, but now there's a new error:
error C2664: 'CreateVideoSurface' : cannot convert parameter 1 from 'struct IDirectDrawSurface7 ** ' to 'struct IDirectDrawSurface7 *'

Share this post


Link to post
Share on other sites
Quote:
Original post by m4ster
hi, I did what u said, but now there's a new error:
error C2664: 'CreateVideoSurface' : cannot convert parameter 1 from 'struct IDirectDrawSurface7 ** ' to 'struct IDirectDrawSurface7 *'


Notice the additional * you need to add to the declaration of the CreateVideoSurface() function after the LPDIRECTDRAWSURFACE:

Quote:
int CreateVideoSurface(LPDIRECTDRAWSURFACE7* lppDDSurface, int nWidth, int nHeight)


Share this post


Link to post
Share on other sites
I did this before and it didn't help,
but your hint that I pass the surface by value was great, now I just pass it by reference and voila ... it works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this