(ERROR) :Create Surface: invalid caps3 specified

Started by
0 comments, last by negcx 20 years, 5 months ago
I am setting up my DirectDraw interfaces with DirectDraw7. However, my call to IDirectDraw7::CreateSurface fails with the error: Direct3D9: (ERROR) :Create surface: invalid caps3 specified Here is the source code:

	HRESULT hResult;
	DDSURFACEDESC2 ddsd;
	DDSCAPS2 ddscaps;

	_hWnd = hWnd;

	if (_Initialized)
		return FALSE;

	hResult = DirectDrawCreateEx (NULL, (LPVOID*) &_DirectDrawPtr, IID_IDirectDraw7, NULL);

	if (FAILED (hResult))
	{
		_DirectDrawPtr = NULL;
		Error (__FILE__, __LINE__);
		return hResult;
	}

	if (Fullscreen)
	{
		hResult = _DirectDrawPtr->SetCooperativeLevel (_hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
		if (FAILED (hResult))
		{
			_DirectDrawPtr->Release ();
			Error (__FILE__, __LINE__);
			return hResult;
		}

		hResult = _DirectDrawPtr->SetDisplayMode (Width, Height, COLOR_DEPTH, 0, 0);
		if (FAILED (hResult))
		{
			_DirectDrawPtr->Release ();
			Error (__FILE__, __LINE__);
			return hResult;
		}
	}
	else
	{
		hResult = _DirectDrawPtr->SetCooperativeLevel (_hWnd, DDSCL_NORMAL);
		if (FAILED (hResult))
		{
			_DirectDrawPtr->Release ();
			Error (__FILE__, __LINE__);
			return hResult;
		}
	}

	ddsd.dwSize = sizeof (ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
	ddsd.dwBackBufferCount = 1;

	hResult = _DirectDrawPtr->CreateSurface (&ddsd, &_PrimarySurfacePtr, NULL);
	if (FAILED (hResult))
	{
		_DirectDrawPtr->Release ();
		Error (__FILE__, __LINE__);
		return hResult;
	}

	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	hResult = _PrimarySurfacePtr->GetAttachedSurface (&ddscaps, &_BackSurfacePtr);
	if (FAILED (hResult))
	{
		_PrimarySurfacePtr->Release ();
		_DirectDrawPtr->Release ();
		Error (__FILE__, __LINE__);
		return hResult;
	}
Any ideas? Thanks, negcx
Advertisement
Figured it out. Turns out I forgot to ZeroMemory() on the structures and they had bogus data in them.

negcx

This topic is closed to new replies.

Advertisement