Problem with Surfaces SOLVED

Started by
3 comments, last by m4ster 17 years, 11 months ago
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]
Advertisement
You're passing LPDIRECTDRAWSURFACE7 by value so the CreateVideoSurface() function won't modify g_lpDDSBackground at all...


Try:

// Hintergrund Image ladenif(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.

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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 *'
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)


Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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.

This topic is closed to new replies.

Advertisement