Sign in to follow this  

Order of calls around D3Ddevice-reset()

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

Here's a function I made for Toggling Fullscreen
bool Display::ToggleFullscreen(int iWidth, int iHeight){
//Precondition: iWidth and iHeight should be whole real integers
//Postcondition: Changes from full screen to window of IWidth and Iheight or vis a versa
	m_bWindowed = !m_bWindowed;

    if(m_bWindowed)
    {
	      SetWindowLong(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
    }
    else
    {
        SetWindowLong(m_hWnd, GWL_STYLE, WS_POPUP|WS_SYSMENU|WS_VISIBLE);
    }

    D3DDISPLAYMODE d3ddm;
    if(FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
        return Error("Could not get the adapter display mode in fullscreen toggle",m_hWnd);

    m_d3dpp.BackBufferCount = 1; 
    m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    m_d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    m_d3dpp.EnableAutoDepthStencil = TRUE; 
    m_d3dpp.AutoDepthStencilFormat = D3DFMT_D16; 
	m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

    if(m_bWindowed)
    {
        m_d3dpp.BackBufferWidth = d3ddm.Width; 
        m_d3dpp.BackBufferHeight = d3ddm.Height;  
        m_d3dpp.BackBufferFormat = d3ddm.Format; 
        m_d3dpp.Windowed = TRUE;  
	}
    else
    {
        m_d3dpp.BackBufferWidth = d3ddm.Width;
        m_d3dpp.BackBufferHeight = d3ddm.Height;
        m_d3dpp.BackBufferFormat = d3ddm.Format;
        m_d3dpp.Windowed = FALSE;  
        m_d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	}
	
       if(!InvalidateObjects())  //Graphics::InvalidateObject()
        return Error("Failed on Invalidate objects",m_hWnd);
	if(!m_pD3dFont->InvalidateFontObject()) //HTFont class
				return Error("Failed FontOnLostDevice",m_hWnd);
	if(!InputFont->InvalidateFontObject())   //HTFont class
		return Error("Failed SpriteOnLostDevice",m_hWnd);
	
	if(!m_pD3DSprite->OnLostDevice())   //ID3DXSprite
		return Error("Failed SpriteOnLostDevice",m_hWnd);
	if(!ResetDevice()) //D3DDevice
		return Error("Failed on resetDevice",m_hWnd);
	if(!m_pD3DSprite->OnResetDevice()) //ID3DXSprite
		return Error("Failed on Sprite OnResetDevice",m_hWnd);
	if(!InputFont->RestoreFontObject()) //HTFont class
		return Error("Failed on Font OnResetDevice",m_hWnd);
	if(!m_pD3dFont->RestoreFontObject()) //HTFont class
		return Error("Failed on Font OnResetDevice",m_hWnd);
	if(!RestoreObjects()) //Graphics::RestoreObjects()
        return FALSE;
    
    if(m_bWindowed)
    {
        SetWindowPos(m_hWnd, 
            HWND_TOP, 
            0,         
            0,    
            iWidth,  
            iHeight, 
            SWP_SHOWWINDOW); 
	}
	
    SetPerspective();

	
/*	Not needed 

	if(m_bWindowed)
    {
		m_iWndHeight=iHeight;
		m_iWndWidth=iWidth;
	
	}
		RECT clientRect;
		GetClientRect(m_hWnd, &clientRect);
		m_iWndWidth = clientRect.right - clientRect.left;
		m_iWndHeight = clientRect.bottom - clientRect.top;
*/
	
	m_iWndWidth = m_d3dpp.BackBufferWidth;
    m_iWndHeight = m_d3dpp.BackBufferHeight;

    return TRUE;

}

Originally I got it from a tutorial, I understood it, you have invalidate your objects, invalidate your Fonts, Do the sprite on lost call, then call the reset, Reset it, then do the opposite. However this doesn't work anymore. Here's five called functions.
 bool HTFont::InvalidateFontObject(){
	if(FAILED(m_pFont->OnLostDevice()))// ID3DXFont type) 
		return false;
	return true;
} 

bool HTFont::RestoreFontObject(){
	if(FAILED(m_pFont->OnResetDevice()))
		return false;
	return true;
}

bool Display::ResetDevice(){
//Precondition: none
//Postcondition: Resets device
    if(FAILED(m_pD3DDevice->Reset(&m_d3dpp)))
        return Error("Reset was called but it failed",m_hWnd);

    return TRUE;
}

bool Display::InvalidateObjects(){
//Precondition: none
//Postcondition: Release sprite interface and then unloads current menu.
	bool temp=unload();
	if(maintplayer!=NULL)
		maintplayer->Getpicture()->unloadavatar();
//	SAFE_RELEASE(m_pD3DSprite);
	return temp;
}

bool Display::RestoreObjects() {
//Precondition: none
//Postcondition: Reload Sprite and Textures.
//	if( FAILED( D3DXCreateSprite( m_pD3DDevice, &m_pD3DSprite ) ) )
//		return Error("Failed to create the D3D Sprite interface",m_hWnd);
	if(maintplayer!=NULL)
		maintplayer->Getpicture()->loadavatar(m_hWnd,m_pD3DDevice);
	return load(-1);
}

So there's my Toggle Fullscreen function. However now after some tweaking crashes on the reset, sometimes the lost device. It changes. However if I comment out
	m_bWindowed = !m_bWindowed;
The code works fine, I'm sure I'm making a very novice mistake here, is there anything jumping out (or once again I must asked is there a better way?) I've been researching this over and over today, and after fixing some other problems perhaps I set this right after making my Device
m_pD3DDevice->SetDialogBoxMode(true);
I don't think this screwed it up but maybe? Is there anything overly apparently wrong? I can show more code if someone needs to see something else.

Share this post


Link to post
Share on other sites
is this the proper way to do the toggle fullscreen? I've seen the DXUT though that seems ultra new, and I'm trying to get decenet compatiblity out of this game (same reason I'm not using the UI Functions)

I also have this thread Click which had other stuff discussed that I'm unsure of(full screen dialog boxes). (Figured only bump one)

Share this post


Link to post
Share on other sites

This topic is 4663 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this