title: DirectX 11 Switching from fullscreen -> windowed problem
body: <p>I've been trawling various sites looking for the correct way to manage switching.</p>
  
  <p>I thought I had cracked it but I've noticed a bizarre issue now that I am setting vertex and pixel shaders for a draw call.</p>
  
  <p>I can swap to full screen using alt-enter and everything is fine, swapping back with either leave a blank window or render correctly but never continue to render any updates.</p>
  
  <p>I.e it'll basically render one frame and any input is registered but not visible on screen till you swap to full screen. </p>
  
  <p>Its clear I'm probably missing something with the swapchain  or devicecontext as I noticed using Flush() it would force it to work however I realize that clearly isn't the solution.</p>
  
  <p>Render function snippet</p>
  
  <pre><code>    cube_.setToContext(context);
      context-&gt;VSSetConstantBuffers( 0, 1, &amp;cb_NeverChanges_ );
      context-&gt;VSSetConstantBuffers( 1, 1, &amp;cb_ResizeChanges_ );
      context-&gt;VSSetConstantBuffers( 2, 1, &amp;cb_FrameChanges_ );
  
      context-&gt;PSSetConstantBuffers( 0, 1, &amp;cb_NeverChanges_ );
      context-&gt;PSSetConstantBuffers( 1, 1, &amp;cb_ResizeChanges_ );
      context-&gt;PSSetConstantBuffers( 2, 1, &amp;cb_FrameChanges_ );
  
      context-&gt;VSSetShader( vertexShader_, nullptr, 0 );
      context-&gt;PSSetShader( pixelShader_, nullptr, 0 );
      context-&gt;Draw(cube_.getVertexTotal(), 0);
  
      dx_.getSwapChain()-&gt;Present(0,0);
  </code></pre>
  
  <p>Resize function which gets passed height/width from WM_SIZE case</p>
  
  <pre><code>if(FAILED(swapChain_-&gt;GetFullscreenState(&amp;fullScreen, nullptr)))
          OutputDebugStringA("Failed to get fullscreen state.\n");
  
      swapChain_-&gt;GetDesc(&amp;swapChainDesc);
      swapChainDesc.Windowed = !fullScreen;
      swapChainDesc.Flags = 0;
      if(fullScreen)
          swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
      //Release renderTarget, depth stencil, depth stencil view, etc
  
      depthStencilView_-&gt;Release();
      depthStencil_-&gt;Release();
      renderTarget_-&gt;Release();
  
      if(FAILED(swapChain_-&gt;ResizeBuffers(swapChainDesc.BufferCount,width,height, swapChainDesc.BufferDesc.Format ,swapChainDesc.Flags)))
      {
          MessageBox( NULL, "Failed to resize buffers.", "Error", MB_OK );
          return false;
      }
  
      //recreate everything that was released
      if(!createRenderTarget())   
          return false;
      if(!createDepthStencils(width,height))
          return false;
  
  
      context_-&gt;OMSetRenderTargets( 1, &amp;renderTarget_, depthStencilView_);
      D3D11_VIEWPORT vp;  //Should be a member of dx!
      vp.Width = (float)width;
      vp.Height = (float)height;
      vp.MinDepth = 0.0f;
      vp.MaxDepth = 1.0f;
      vp.TopLeftX = 0;
      vp.TopLeftY = 0;
      context_-&gt;RSSetViewports( 1, &amp;vp );
  </code></pre>
  
  <p>Swap Chain setup with this </p>
  
  <pre><code>    DXGI_SWAP_CHAIN_DESC swapChainDesc;
  ZeroMemory( &amp;swapChainDesc, sizeof( swapChainDesc ) );
  swapChainDesc.BufferCount = 1;
  swapChainDesc.BufferDesc.Width = width;
  swapChainDesc.BufferDesc.Height = height; 
  swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; //auto =0, originally 60
  swapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
  swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  swapChainDesc.OutputWindow = hWnd;
  swapChainDesc.SampleDesc.Count = 1;
  swapChainDesc.SampleDesc.Quality = 0;
  swapChainDesc.Windowed = TRUE;
  </code></pre>
  
  <p>I've been testing this with D3D11_CREATE_DEVICE_DEBUG and no errors/warnings/leaks, any comments or input welcome. </p>