about CEGUI LostDevice!

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

jasonjzz
Not too shy to talk
Not too shy to talk
Posts: 40
Joined: Mon Dec 22, 2008 06:37

about CEGUI LostDevice!

Postby jasonjzz » Sat Mar 20, 2010 10:18

I using the CEGUI on our project.


myd8.h:

Code: Select all

class CD3DManager
{
public:
   CD3DManager(IDirect3DDevice8 *pD3Ddev, myIDirect3DDevice8 *pParent)
   {
      m_pParent = pParent;
      m_pD3Ddev = pD3Ddev;
   }
   ~CD3DManager() {}

   HRESULT Initialize();
   HRESULT PreReset();
   HRESULT PostReset();
   HRESULT Release();

   myIDirect3DDevice8* GetD3DDevice() { return m_pParent; };

private:
   myIDirect3DDevice8   *m_pParent;
   IDirect3DDevice8   *m_pD3Ddev;   
};



interface myIDirect3DDevice8 : public IDirect3DDevice8
{
public:
   myIDirect3DDevice8(IDirect3DDevice8 **ppReturnedDeviceInterface, D3DPRESENT_PARAMETERS *pPresentParam, IDirect3D8 *pIDirect3D8)
   {
      m_pD3Ddev = *ppReturnedDeviceInterface;
      *ppReturnedDeviceInterface = this;
      m_PresentParam = *pPresentParam;
      m_pD3Dint = pIDirect3D8;

      m_pManager = new CD3DManager(m_pD3Ddev, this);
      m_pManager->Initialize();

      m_refCount = 1;
   }

   IDirect3DDevice8 *m_pD3Ddev;
   LPDIRECT3DDEVICE8 m_device;
   IDirect3D8 *m_pD3Dint;

   UINT m_refCount;

   D3DPRESENT_PARAMETERS m_PresentParam;

   CD3DManager *m_pManager;

   

    STDMETHOD(QueryInterface)(THIS_ REFIID riid, void** ppvObj);
    STDMETHOD_(ULONG,AddRef)(THIS);
    STDMETHOD_(ULONG,Release)(THIS);
    STDMETHOD(TestCooperativeLevel)(THIS);
    STDMETHOD_(UINT, GetAvailableTextureMem)(THIS);
    STDMETHOD(ResourceManagerDiscardBytes)(THIS_ DWORD Bytes);
    STDMETHOD(GetDirect3D)(THIS_ IDirect3D8** ppD3D8);
    STDMETHOD(GetDeviceCaps)(THIS_ D3DCAPS8* pCaps);
    STDMETHOD(GetDisplayMode)(THIS_ D3DDISPLAYMODE* pMode);
    ……………………
    ……………………
    ……………………
    STDMETHOD(DeletePatch)(THIS_ UINT Handle);
};



myd8.cpp:

Code: Select all

using namespace myUI;

myUI::myCEGUI *g_pCEGUIRender = NULL;

HRESULT CD3DManager::Initialize()
{
   g_pCEGUIRender = new myUI(m_pParent);
   return S_OK;
}

HRESULT CD3DManager::PreReset()
{
   CEGUI::Renderer *pRenderer = CEGUI::System::getSingleton().getRenderer();
   CEGUI::DirectX81Renderer* d3d_renderer = static_cast<CEGUI::DirectX81Renderer*>(pRenderer);
   if (pRenderer != NULL && d3d_renderer != NULL)
   {
      d3d_renderer->preD3DReset();
   }
   return S_OK;
}

HRESULT CD3DManager::PostReset()
{
   CEGUI::Renderer *pRenderer = CEGUI::System::getSingleton().getRenderer();
   CEGUI::DirectX81Renderer* d3d_renderer = static_cast<CEGUI::DirectX81Renderer*>(pRenderer);
   if (pRenderer != NULL && d3d_renderer != NULL)
   {
      d3d_renderer->postD3DReset();
   }
   return S_OK;
}

HRESULT CD3DManager::Release()
{
   return S_OK;
}

//-----------------------------------------------------------------------------

HRESULT APIENTRY myIDirect3DDevice8::QueryInterface(REFIID riid, void** ppvObj)
{
   return m_pD3Ddev->QueryInterface(riid, ppvObj);
}

ULONG APIENTRY myIDirect3DDevice8::AddRef(void)
{
   m_refCount++;
   return m_pD3Ddev->AddRef();
}

……………………

……………………

HRESULT APIENTRY myIDirect3DDevice8::Reset(D3DPRESENT_PARAMETERS* pPresentationParameters)
{
   m_pManager->PreReset();

   HRESULT hRet = m_pD3Ddev->Reset(pPresentationParameters);

   if( SUCCEEDED(hRet) )
   {
      m_PresentParam = *pPresentationParameters;
      m_pManager->PostReset();
   }

   return hRet;    
}


……………………

……………………

HRESULT APIENTRY myIDirect3DDevice8::BeginScene(void)
{
   return m_pD3Ddev->BeginScene();
}

HRESULT APIENTRY myIDirect3DDevice8::EndScene(void)
{

   g_pCEGUIRender->mygui_Render();

   return m_pD3Ddev->EndScene();



}


mycegui.h :

Code: Select all

#include "CEGUI.h"
#include "renderer.h"         // D3D8 CEGUIRenderer
#include <fstream>

using namespace std;
using namespace CEGUI;



namespace myUI
{

   class myUI_EXPORT myCEGUI
   {
   public:
      myCEGUI(IDirect3DDevice8 *pd3dDevice);
      virtual ~myCEGUI();

   public:
      virtual void mygui_Render(void);
      LRESULT my_WndProc(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam);

   public:
      static myCEGUI* my_GetMe(void) { return m_pSMe; };

   protected:
      Renderer      *m_pGUIRenderer;
      CEGUI::Window *m_pLayout;

}


These are just some of my project code,My intention is to want to CEGUI embedded inside the game.
The results have been successful.
but,if I change the EndScene() function,like this:

Code: Select all

HRESULT APIENTRY myIDirect3DDevice8::EndScene(void)
{

   LPDIRECT3DVERTEXBUFFER8 d_buffer;
   UINT stride;
   DWORD VERTEX_FVF;
   m_pD3Ddev->GetStreamSource(0, &d_buffer, &stride);
   m_pD3Ddev->GetVertexShader(&VERTEX_FVF);

   // set device states
   DWORD zenable, fillmode, alphatestenable, zwriteenable, fogenable, cullmode;
   m_pD3Ddev->GetRenderState(D3DRS_ZENABLE, &zenable);
   m_pD3Ddev->GetRenderState(D3DRS_FILLMODE, &fillmode);
   m_pD3Ddev->GetRenderState(D3DRS_ALPHATESTENABLE, &alphatestenable);
   m_pD3Ddev->GetRenderState(D3DRS_ZWRITEENABLE, &zwriteenable);
   m_pD3Ddev->GetRenderState(D3DRS_FOGENABLE, &fogenable);
   m_pD3Ddev->GetRenderState(D3DRS_CULLMODE, &cullmode);

   // setup texture addressing settings
   DWORD addressu, addressv;
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_ADDRESSU, &addressu);
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_ADDRESSV, &addressv);

   // setup colour calculations
   DWORD  colorarg1, colorarg2, colorop;
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_COLORARG1, &colorarg1);
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_COLORARG2, &colorarg2);
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_COLOROP, &colorop);

   // setup alpha calculations
   DWORD alphaarg1, alphaarg2, alphaop;
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_ALPHAARG1, &alphaarg1);
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_ALPHAARG2, &alphaarg2);
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_ALPHAOP, &alphaop);

   // setup filtering
   DWORD minfilter, magfilter;
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_MINFILTER, &minfilter);
   m_pD3Ddev->GetTextureStageState(0, D3DTSS_MAGFILTER, &magfilter);

   // disable texture stages we do not need.
   DWORD colorop1;
   m_pD3Ddev->GetTextureStageState(1, D3DTSS_COLOROP, &colorop1);

   // setup scene alpha blending
   DWORD alphablendenable, srcblend, destblend;
   m_pD3Ddev->GetRenderState(D3DRS_ALPHABLENDENABLE, &alphablendenable);
   m_pD3Ddev->GetRenderState(D3DRS_SRCBLEND, &srcblend);
   m_pD3Ddev->GetRenderState(D3DRS_DESTBLEND, &destblend);


   g_pCEGUIRender->mygui_Render();


   m_pD3Ddev->SetStreamSource(0, d_buffer, stride);
   m_pD3Ddev->SetVertexShader(VERTEX_FVF);

   // set device states
   m_pD3Ddev->SetRenderState(D3DRS_ZENABLE, zenable);
   m_pD3Ddev->SetRenderState(D3DRS_FILLMODE, fillmode);
   m_pD3Ddev->SetRenderState(D3DRS_ALPHATESTENABLE, alphatestenable);
   m_pD3Ddev->SetRenderState(D3DRS_ZWRITEENABLE, zwriteenable);
   m_pD3Ddev->SetRenderState(D3DRS_FOGENABLE, fogenable);
   m_pD3Ddev->SetRenderState(D3DRS_CULLMODE, cullmode);

   // setup texture addressing settings
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_ADDRESSU, addressu);
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_ADDRESSV, addressv);

   // setup colour calculations
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_COLORARG1, colorarg1);
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_COLORARG2, colorarg2);
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_COLOROP, colorop);

   // setup alpha calculations
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_ALPHAARG1, alphaarg1);
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_ALPHAARG2, alphaarg2);
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_ALPHAOP, alphaop);

   // setup filtering
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_MINFILTER, minfilter);
   m_pD3Ddev->SetTextureStageState(0, D3DTSS_MAGFILTER, magfilter);

   // disable texture stages we do not need.
   m_pD3Ddev->SetTextureStageState(1, D3DTSS_COLOROP, colorop1);

   // setup scene alpha blending
   m_pD3Ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, alphablendenable);
   m_pD3Ddev->SetRenderState(D3DRS_SRCBLEND, srcblend);
   m_pD3Ddev->SetRenderState(D3DRS_DESTBLEND, destblend);

   return m_pD3Ddev->EndScene();



}



when I (Alt + Tab) switch the window. the Game.exe is Crash!

I think it should be lostDevice!

I tried to solve ,but still dont OK , I need help!!

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: about CEGUI LostDevice!

Postby CrazyEddie » Sun Mar 21, 2010 07:00

Ok. I'm no expert on this stuff; I don't develop on Windows all that much these days.

The issue is regarding lost devices and an inability to reset the device, it is likely caused by some resource you're obtaining a reference to that is not getting released. I think it's probably the interface returned here:

Code: Select all

m_pD3Ddev->GetStreamSource(0, &d_buffer, &stride);

You probably need to call Release() on that after setting it back as the stream source.

CE.

jasonjzz
Not too shy to talk
Not too shy to talk
Posts: 40
Joined: Mon Dec 22, 2008 06:37

Re: about CEGUI LostDevice!

Postby jasonjzz » Sun Mar 21, 2010 13:45


jasonjzz
Not too shy to talk
Not too shy to talk
Posts: 40
Joined: Mon Dec 22, 2008 06:37

Re: about CEGUI LostDevice!

Postby jasonjzz » Mon Mar 22, 2010 05:54

please CE help me!

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: about CEGUI LostDevice!

Postby CrazyEddie » Mon Mar 22, 2010 07:19

jasonjzz wrote:please CE help me!

There's no need for this. Once you've asked your question it will be seen eventually, bumping posts like this just antagonises me ;) You should know that I don't always come here more than once a day. For example, I can tell you that I'll not be on any more today, and it's likely that I'll not be on at all tomorrow ;)

The assertion failure tells me that you're instantiating some CEGUI singleton more than once. Ensure you're not inadvertently calling the code that creates CEGUI::System more than once.

HTH

CE.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 21 guests