Jump to content
  • Advertisement

Archived

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

Stibmit

Second surface fails to obtain DC...?

This topic is 5934 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alrighty, here''s the scoop- I have two surfaces. The first surface is created, it obtains its DC, Gets the bitmap BitBlt() on the first surface, and then released the DC. I do the exact same thing with the second surface I use, but with a different bitmap and everything, however, the program crashes when the second surface tries to obtain the same DC. Here''s the code...
  
//load in the bitmap

	gcDraw.SetupBitmap(NULL, "Image_1.bmp");
	//create the first surface

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
	ddsd.dwWidth = gcDraw.GetWidth();
	ddsd.dwHeight = gcDraw.GetHeight();
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;

	lpdd->CreateSurface(&ddsd, &lpddPicture1, NULL);
	//blt the picture onto the offscreen

	HDC hdc;
	lpddPicture1->GetDC(&hdc);
	BitBlt(hdc, 0, 0, gcDraw.GetWidth(), gcDraw.GetHeight(), gcDraw, 0, 0, SRCCOPY);
	lpddPicture1->ReleaseDC(hdc);

	//reset the gdi canvas

	gcDraw.GDICanvas_Reset();

	//load in the second bitmap

	gcDraw.SetupBitmap(NULL, "Image_2.bmp");
	//create the second surface

	memset(&ddsd, 0, sizeof(ddsd));
	ddsd.dwSize=sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
	ddsd.dwWidth = gcDraw.GetWidth();
	ddsd.dwHeight = gcDraw.GetHeight();
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
	
	lpdd->CreateSurface(&ddsd, &lpddPicture2, NULL);
	MessageBox(hwnd, "Right before surface 2 gets dc", "Check Point", MB_OK);
	lpddPicture2->GetDC(&hdc); //this is where the error occurs

	MessageBox(hwnd, "Right AFTER surface 2 gets dc", "Check Point", MB_OK);
	BitBlt(hdc, 0, 0, gcDraw.GetWidth(), gcDraw.GetHeight(), gcDraw, 0, 0, SRCCOPY);
	lpddPicture2->ReleaseDC(hdc);
  
What is it that I''m doing wrong which causes the program to crash when the second surface tries to obtain the dc? Thanks to anyone who takes the time to help me...

Share this post


Link to post
Share on other sites
Advertisement
Did you check the return value of CreateSurface? It probably failed. I''m guessing you ran out of video memory. You can also create surfaces in system memory using the DDSCAPS_SYSTEMMEMORY option. In fact, if you plan on accessing (reading) the data on this surface, you should create it in system memory. Reading directly from the video memory is supposedly very slow, depending on the display.

BTW: I wrote a routine that will translate some of the DirectX errors into messages. I couldn''t find a built-in function or array that had this translation, so you can try mine. I''m sure it doesn''t have all the errors, but it has a lot of the common ones:

  
char *DDErrToMsg(long int code)
{
char *str;

switch (code)
{
case DDERR_ALREADYINITIALIZED:
str = "This object is already initialized";
break;
case DDERR_CANNOTATTACHSURFACE:
str = "This surface can not be attached to the requested surface";
break;
case DDERR_CANNOTDETACHSURFACE:
str = "This surface can not be detached from the requested surface";
break;
case DDERR_CURRENTLYNOTAVAIL:
str = "Support is currently not available.";
break;
case DDERR_EXCEPTION:
str = "An exception was encountered while performing the requested operation";
break;
case DDERR_GENERIC:
str = "Generic failure";
break;
case DDERR_HEIGHTALIGN:
str = "Height of rectangle provided is not a multiple of reqd alignment";
break;
case DDERR_INCOMPATIBLEPRIMARY:
str = "Unable to match primary surface creation request with existing primary surface";
break;
case DDERR_INVALIDCAPS:
str = "One or more of the caps bits passed to the callback are incorrect.";
break;
case DDERR_INVALIDCLIPLIST:
str = "DirectDraw does not support provided Cliplist";
break;
case DDERR_INVALIDMODE:
str = "DirectDraw does not support the requested mode";
break;
case DDERR_INVALIDOBJECT:
str = "DirectDraw received a pointer that was an invalid DIRECTDRAW object";
break;
case DDERR_INVALIDPARAMS:
str = "One or more of the parameters passed to the callback function are incorrect";
break;
case DDERR_INVALIDPIXELFORMAT:
str = "pixel format was invalid as specified";
break;
case DDERR_INVALIDRECT:
str = "Rectangle provided was invalid.";
break;
case DDERR_LOCKEDSURFACES:
str = "Operation could not be carried out because one or more surfaces are locked";
break;
case DDERR_NO3D:
str = "There is no 3D present.";
break;
case DDERR_NOALPHAHW:
str = "Operation could not be carried out because there is no alpha accleration hardware present or available";
break;
case DDERR_NOCLIPLIST:
str = "no clip list available";
break;
case DDERR_NOCOLORCONVHW:
str = "Operation could not be carried out because there is no color conversion hardware present or available.";
break;
case DDERR_NOCOOPERATIVELEVELSET:
str = "Create function called without DirectDraw object method SetCooperativeLevel being called.";
break;
case DDERR_NOCOLORKEY:
str = "Surface doesn''t currently have a color key";
break;
case DDERR_NOCOLORKEYHW:
str = "Operation could not be carried out because there is no hardware support of the dest color key";
break;
case DDERR_NODIRECTDRAWSUPPORT:
str = "No DirectDraw support possible with current display driver";
break;
case DDERR_NOEXCLUSIVEMODE:
str = "Operation requires the application to have exclusive mode but the application does not have exclusive mode";
break;
case DDERR_NOFLIPHW:
str = "Flipping visible surfaces is not supported.";
break;
case DDERR_NOGDI:
str = "There is no GDI present.";
break;
case DDERR_NOMIRRORHW:
str = "Operation could not be carried out because there is no hardware present or available";
break;
case DDERR_NOTFOUND:
str = "Requested item was not found";
break;
case DDERR_NOOVERLAYHW:
str = "Operation could not be carried out because there is no overlay hardware present or available";
break;
case DDERR_NORASTEROPHW:
str = "Operation could not be carried out because there is no appropriate raster op hardware present or available";
break;
case DDERR_NOROTATIONHW:
str = "Operation could not be carried out because there is no rotation hardware present or available";
break;
case DDERR_NOSTRETCHHW:
str = "Operation could not be carried out because there is no hardware support for stretching";
break;
case DDERR_NOT4BITCOLOR:
str = "DirectDrawSurface is not in 4 bit color palette and the requested operation requires 4 bit color palette";
break;
case DDERR_NOT4BITCOLORINDEX:
str = "DirectDrawSurface is not in 4 bit color index palette and the requested operation requires 4 bit color index palette";
break;
case DDERR_NOT8BITCOLOR:
str = "DirectDraw Surface is not in 8 bit color mode and the requested operation requires 8 bit color";
break;
case DDERR_NOTEXTUREHW:
str = "Operation could not be carried out because there is no texture mapping hardware present or available";
break;
case DDERR_NOVSYNCHW:
str = "Operation could not be carried out because there is no hardware support for vertical blank synchronized operations";
break;
case DDERR_NOZBUFFERHW:
str = "Operation could not be carried out because there is no hardware support for zbuffer blting.";
break;
case DDERR_NOZOVERLAYHW:
str = "Overlay surfaces could not be z layered based on their BltOrder because the hardware does not support z layering of overlays";
break;
case DDERR_OUTOFCAPS:
str = "The hardware needed for the requested operation has already been allocated.";
break;
case DDERR_OUTOFMEMORY:
str = "DirectDraw does not have enough memory to perform the operation.";
break;
case DDERR_OUTOFVIDEOMEMORY:
str = "DirectDraw does not have enough memory to perform the operation.";
break;
case DDERR_OVERLAYCANTCLIP:
str = "hardware does not support clipped overlays";
break;
case DDERR_OVERLAYCOLORKEYONLYONEACTIVE:
str = "Can only have ony color key active at one time for overlays";
break;
case DDERR_PALETTEBUSY:
str = "Access to this palette is being refused because the palette is already locked by another thread";
break;
case DDERR_COLORKEYNOTSET:
str = "No src color key specified for this operation.";
break;
case DDERR_SURFACEALREADYATTACHED:
str = "This surface is already attached to the surface it is being attached to.";
break;
case DDERR_SURFACEALREADYDEPENDENT:
str = "This surface is already attached to the surface it is being attached to.";
break;
case DDERR_SURFACEBUSY:
str = "Access to this surface is being refused because the surface is already locked by another thread";
break;
case DDERR_CANTLOCKSURFACE:
str = "Access to this surface is being refused because no driver exists which can supply a pointer to the surface";
break;
case DDERR_SURFACEISOBSCURED:
str = "Access to Surface refused because Surface is obscured.";
break;
case DDERR_SURFACELOST:
str = "Access to this surface is being refused because the surface is gone. The DIRECTDRAWSURFACE object representing this surface should have Restore called on it";
break;
case DDERR_SURFACENOTATTACHED:
str = "The requested surface is not attached";
break;
case DDERR_TOOBIGHEIGHT:
str = "Height requested by DirectDraw is too large.";
break;
case DDERR_TOOBIGSIZE:
str = "Size requested by DirectDraw is too large -- The individual height and width are OK";
break;
case DDERR_TOOBIGWIDTH:
str = "Width requested by DirectDraw is too large";
break;
case DDERR_UNSUPPORTED:
str = "Action not supported.";
break;
case DDERR_UNSUPPORTEDFORMAT:
str = "FOURCC format requested is unsupported by DirectDraw";
break;
case DDERR_UNSUPPORTEDMASK:
str = "Bitmask in the pixel format requested is unsupported by DirectDraw";
break;
case DDERR_VERTICALBLANKINPROGRESS:
str = "vertical blank is in progress";
break;
case DDERR_WASSTILLDRAWING:
str = "Informs DirectDraw that the previous Blt which is transfering information to or from this Surface is incomplete";
break;
case DDERR_XALIGN:
str = "Rectangle provided was not horizontally aligned on reqd. boundary";
break;
case DDERR_INVALIDDIRECTDRAWGUID:
str = "The GUID passed to DirectDrawCreate is not a valid DirectDraw driver identifier.";
break;
case DDERR_DIRECTDRAWALREADYCREATED:
str = "A DirectDraw object representing this driver has already been created for this process";
break;
case DDERR_NODIRECTDRAWHW:
str = "A DirectDraw object representing this driver has already been created for this process";
break;
case DDERR_PRIMARYSURFACEALREADYEXISTS:
str = "this process already has created a primary surface";
break;
case DDERR_NOEMULATION:
str = "software emulation not available";
break;
case DDERR_REGIONTOOSMALL:
str = "region passed to Clipper::GetClipList is too small.";
break;
case DDERR_CLIPPERISUSINGHWND:
str = "an attempt was made to set a clip list for a clipper objec that is already monitoring an hwnd.";
break;
case DDERR_NOCLIPPERATTACHED:
str = "No clipper object attached to surface object";
break;
case DDERR_NOHWND:
str = "Clipper notification requires an HWND or no HWND has previously been set as the CooperativeLevel HWND";
break;
case DDERR_HWNDSUBCLASSED:
str = "HWND used by DirectDraw CooperativeLevel has been subclassed, this prevents DirectDraw from restoring state";
break;
case DDERR_HWNDALREADYSET:
str = "The CooperativeLevel HWND has already been set. It can not be reset while the process has surfaces or palettes created.";
break;
case DDERR_NOPALETTEATTACHED:
str = "No palette object attached to this surface";
break;
case DDERR_NOPALETTEHW:
str = "No hardware support for 16 or 256 color palettes";
break;
case DDERR_BLTFASTCANTCLIP:
str = "If a clipper object is attached to the source surface passed into a BltFast call.";
break;
case DDERR_NOBLTHW:
str = "No blter.";
break;
case DDERR_NODDROPSHW:
str = "No DirectDraw ROP hardware.";
break;
case DDERR_OVERLAYNOTVISIBLE:
str = "returned when GetOverlayPosition is called on a hidden overlay";
break;
case DDERR_NOOVERLAYDEST:
str = "returned when GetOverlayPosition is called on a overlay that UpdateOverlay has never been called on to establish a destionation";
break;
case DDERR_INVALIDPOSITION:
str = "returned when the position of the overlay on the destionation is no longer legal for that destionation";
break;
case DDERR_NOTAOVERLAYSURFACE:
str = "returned when an overlay member is called for a non-overlay surface";
break;
case DDERR_EXCLUSIVEMODEALREADYSET:
str = "An attempt was made to set the cooperative level when it was already set to exclusive";
break;
case DDERR_NOTFLIPPABLE:
str = "An attempt has been made to flip a surface that is not flippable.";
break;
case DDERR_CANTDUPLICATE:
str = "Can''t duplicate primary & 3D surfaces, or surfaces that are implicitly created";
break;
case DDERR_NOTLOCKED:
str = "Surface was not locked. An attempt to unlock a surface that was not locked at all, or by this process, has been attempted";
break;
case DDERR_CANTCREATEDC:
str = "Windows can not create any more DCs";
break;
case DDERR_NODC:
str = "No DC was ever created for this surface.";
break;
case DDERR_WRONGMODE:
str = "This surface can not be restored because it was created in a different mode";
break;
case DDERR_IMPLICITLYCREATED:
str = "This surface can not be restored because it is an implicitly created surface";
break;
case DDERR_NOTPALETTIZED:
str = "The surface being used is not a palette-based surface";
break;
case DDERR_UNSUPPORTEDMODE:
str = "The display is currently in an unsupported mode";
break;
case DDERR_NOMIPMAPHW:
str = "Operation could not be carried out because there is no mip-map texture mapping hardware present or available";
break;
case DDERR_INVALIDSURFACETYPE:
str = "The requested action could not be performed because the surface was of the wrong type";
break;
case DDERR_DCALREADYCREATED:
str = "A DC has already been returned for this surface. Only one DC can be retrieved per surface";
break;
case DDERR_CANTPAGELOCK:
str = "The attempt to page lock a surface failed.";
break;
case DDERR_CANTPAGEUNLOCK:
str = "The attempt to page unlock a surface failed.";
break;
case DDERR_NOTPAGELOCKED:
str = "An attempt was made to page unlock a surface with no outstanding page locks.";
break;
case DDERR_NOTINITIALIZED:
str = "An attempt was made to invoke an interface member of a DirectDraw object created by CoCreateInstance() before it was initialized.";
break;
default:
str = "";
};

return str;
}

[\source]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!