Jump to content
  • Advertisement
Sign in to follow this  
Moktail

Problem creating a surface

This topic is 4057 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

I keep getting a runtime error when I try to create a surface. This is where I create the surface. Does something seem odd? /* Create the surface */ if(FAILED(m_pD3DDevice->CreateImageSurface(256, 256, (D3DFORMAT)m_pD3DFormat,&m_pD3DSurface))) { return E_FAIL; } What could be some reasons why its failing? If you would like to see the rest of the code I will post it up. I am just trying to create a simple window with a surface. Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
What type is m_pD3DFormat? Why do you need to cast it?

Also, what kind of runtime error do you get? an access violation? something else?

Share this post


Link to post
Share on other sites
I'd put money on m_pD3DDevice being NULL. Use the debugger to step through your code and find out where/why it's a NULL pointer and you'll have the true source of your error...

hth
Jack

Share this post


Link to post
Share on other sites
Well, I realized that it is NULL. Here is the function where I used it.

/* Initialize Direct3d */
HRESULT D3DWindow::SetupDirect3D(void)
{
/* Create the Direct3D object */
if(NULL == (m_pD3D = Direct3DCreate8(D3D_SDK_VERSION)))
{
return E_FAIL;
}

/* Get the current display mode so we can know what bitdepth
we are */
D3DDISPLAYMODE d3ddm;
if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,
&d3ddm)))
{
return E_FAIL;
}

/* Fill in the present parameters */
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
/* We want windowed mode */
d3dpp.Windowed = TRUE;
/* Discard this */
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
/*Same format as the current format
(we got this from g_pD3D->GetAdapterDisplayMode) */
d3dpp.BackBufferFormat = d3ddm.Format;

/* Create the device */
if(FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
m_hWindow,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&m_pD3DDevice)))
{
return E_FAIL;
}

/* Create the surface */
if(FAILED(m_pD3DDevice->CreateImageSurface(256, 256,
(D3DFORMAT)m_pD3DFormat,
&m_pD3DSurface)))
{
return E_FAIL;
}

/* Lock the surface */
D3DLOCKED_RECT kLockedRect;
m_pD3DSurface->LockRect(&kLockedRect, NULL, 0);

/* Cast a pointer to point to the first pixel */
DWORD* piSurfaceBuffer = (DWORD*) kLockedRect.pBits;

/* Fill surface */
int iX, iY;
for(iY = 0; iY < 256; ++iY)
{
for(iX = 0; iX < 256; ++iX)
{
/* Form a pattern */
int iPower = (int)( sin(static_cast<double>(iY * iX)) * 128 + cos(static_cast<double>(iY * -iX)) * 128);
piSurfaceBuffer[iX + iY*(kLockedRect.Pitch >> 2)] =
D3DCOLOR_XRGB(iPower, iPower, iPower);
}
}

/* Unlock */
m_pD3DSurface->UnlockRect();

return D3D_OK;
}

What can I set it to to get the program to run?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!