Archived

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

Reset Question (with pretty pics!)

This topic is 5111 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'm having a reset problem that's simply causing all my textures to become black. I have no clue why, because it just randomly picked up one day and started doing this (it had been working perfectly). Another intresting observation, is that it appears to only be MESH textures, since my 2D ones are still there, and I've also verified that the level still exists (I still run into walls and the like). Could this have anything to do with me going from 9.0b to 9.0b with the summer update (I realized some other problems during this change)? Anyway, for what it's worth, here's some screenshots and relevant code: BeforeAfter
void ToggleFullscreen()
{
	FullScreenMode = !FullScreenMode;
	if(FullScreenMode)
	{
		D3DDISPLAYMODE d3ddm;
		g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
		ZeroMemory( &g_d3dpp, sizeof(g_d3dpp) );
		g_d3dpp.Windowed               = FALSE;
		g_d3dpp.EnableAutoDepthStencil = TRUE;
		g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		g_d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
		g_d3dpp.BackBufferWidth        = DEVICEWIDTH;
		g_d3dpp.BackBufferHeight       = DEVICEHEIGHT;
		g_d3dpp.BackBufferFormat       = D3DFMT_A8R8G8B8;
		g_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
		g_d3dpp.FullScreen_RefreshRateInHz = d3ddm.RefreshRate;
		g_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
		SetWindowLong(hWnd, GWL_STYLE, WS_POPUP|WS_SYSMENU|WS_VISIBLE);
        SetWindowPos( hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW );
		ShowCursor(FALSE);
		g_pd3dDevice->ShowCursor(FALSE);
	}
	else
	{
		ZeroMemory( &g_d3dpp, sizeof(g_d3dpp) );
		g_d3dpp.Windowed = TRUE;
		g_d3dpp.EnableAutoDepthStencil = TRUE;
		g_d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		g_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		g_d3dpp.BackBufferWidth        = DEVICEWIDTH;
		g_d3dpp.BackBufferHeight       = DEVICEHEIGHT;
		g_d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
		g_d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

		SetWindowLong(hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
		SetWindowPos(hWnd, HWND_NOTOPMOST, WINDOWX, WINDOWY, DEVICEWIDTH, DEVICEHEIGHT, SWP_SHOWWINDOW);
		ShowCursor(TRUE);
		g_pd3dDevice->ShowCursor(TRUE);
	}
	InvalidateDeviceObjs();
	HRESULT hr = g_pd3dDevice->Reset(&g_d3dpp);
	if(FAILED(hr))
	{
		MessageBox(hWnd, "Toggle Failed!", "[DirectX Error]", MB_OK);
		PostQuitMessage(0);
	}
	RestoreDeviceObjs();
}
and
void MESH::InitMesh(LPDIRECT3DDEVICE9 pd3dDevice, char* strPath)
{
	m_pd3dDevice = pd3dDevice;
	D3DXLoadMeshFromX( strPath, D3DXMESH_SYSTEMMEM, pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL, &m_dwNumMaterials, &m_pMesh );
	m_NumVertices = m_pMesh->GetNumVertices();
	D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    m_pMeshMaterials = new D3DMATERIAL9[m_dwNumMaterials];
    m_pMeshTextures  = new LPDIRECT3DTEXTURE9[m_dwNumMaterials];

    for( DWORD i=0; i<m_dwNumMaterials; i++ )
    {
        m_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

        m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;

        m_pMeshTextures[i] = NULL;
        if( d3dxMaterials[i].pTextureFilename != NULL && lstrlen(d3dxMaterials[i].pTextureFilename) > 0 )
        {
				string newfilename = "meshes//textures//";

				newfilename += d3dxMaterials[i].pTextureFilename;
				LPSTR newfilenamestr = (char*)(newfilename.c_str());
				D3DXCreateTextureFromFileEx( pd3dDevice, newfilenamestr, 0, 0, 0, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0 ,255), NULL, NULL, &m_pMeshTextures[i]);
		}
	}
	Initialized = true;
}
Edit: Pictures were enormous [edited by - ms291052 on December 15, 2003 1:54:54 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Ok i dont know much and u may be doing this somewhere else in the code but i had to reset the camera stuff ???? sry if this dont help i dont know any thing else

Share this post


Link to post
Share on other sites
Your code looks OK. You load the mesh with D3DXMESH_SYSTEMMEM which should keep in in system memory. Try if changing that to D3DXMESH_MANAGED helps.

[edited by - Fidelio66 on December 15, 2003 4:11:20 PM]

Share this post


Link to post
Share on other sites