   Strange issue with DirectX and wxWidgets
  Hello, I have been using DirectX and wxWidgets together for some time now and have had no issues. However, once I started to tackle resizing the window, I generated a big problem.Basically here is what happens, I can resize the window just fine, however, once I use the D3DObject after that (to say, create a vertex buffer), my rendering just dies and I have no clue why. I think maybe I am recreating the object wrong. Here was my test casesGood:1) Create the window, make sure comment out all onSize code.2) Use the D3DObject to create a vertex buffer3) Success, it is a valid vertex buffer and I can still renderGood:1) Create the window, make sure all onSize code is on2) Resize the window3) Will still renderBad:1) Create the window, make sure all onSize code is on2) Resize the window3) Create a vertex buffer4) Rendering does not crash the program, but just nothing will display (it will just show the wxPanel)On all of the resizing and the creating of the vertex buffer I will get "S_OK" as the return code, so no errors are being thrown.Here is a snippet of my resizing code void CRenderCanvas::onSize(wxSizeEvent& event){wxSize newSize = GetSize();m_PresentParams.BackBufferWidth= newSize.x;m_PresentParams.BackBufferHeight = newSize.y;m_lpSprite->OnLostDevice();m_lpDirect3DDevice9->Reset(&m_PresentParams);m_lpSprite->OnResetDevice();}After that onSize, I did only a "m_pRenderCanvas->m_lpDirect3DDevice9->CreateVertexBuffer(4*12, 0, 0, D3DPOOL_DEFAULT, &pDirectXVB, 0);" and then rendering will no longer be displayed. Here is all of my RenderCanvas code, in case I did something wrong else where#include "RenderCanvas.h"BEGIN_EVENT_TABLE(CRenderCanvas, wxWindow)EVT_SIZE(CRenderCanvas::onSize)EVT_PAINT(CRenderCanvas::onPaint)END_EVENT_TABLE()CRenderCanvas::CRenderCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name): wxWindow(parent, id, pos, size, style|wxFULL_REPAINT_ON_RESIZE, name){}void CRenderCanvas::BuildD3D(HWND hWnd, int nWidth, int nHeight){if(hWnd == 0){char buf[2048];sprintf (buf, "HWND is not valid");MessageBoxA(0, buf, "FAILED", MB_OK);}m_lpDirect3DObject = Direct3DCreate9(D3D_SDK_VERSION);if(m_lpDirect3DObject == 0){char buf[2048];sprintf (buf, "Failed to create the DirectX 9 object");MessageBoxA(0, buf, "FAILED", MB_OK);}ZeroMemory(&m_PresentParams, sizeof(D3DPRESENT_PARAMETERS));m_PresentParams.hDeviceWindow = hWnd;m_PresentParams.Windowed = true;m_PresentParams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;m_PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD;m_PresentParams.EnableAutoDepthStencil = true;m_PresentParams.AutoDepthStencilFormat = D3DFMT_D16;if(FAILED(m_lpDirect3DObject->CreateDevice(0, D3DDEVTYPE_HAL, hWnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&m_PresentParams, &m_lpDirect3DDevice9))){char buf[2048];sprintf (buf, "Failed to create the DirectX 9 device");MessageBoxA(0, buf, "FAILED", MB_OK);}if(FAILED(D3DXCreateSprite(m_lpDirect3DDevice9, &m_lpSprite))){char buf[2048];sprintf (buf, "Failed to create the DirectX 9 sprite");MessageBoxA(0, buf, "FAILED", MB_OK);}m_lpDirect3DDevice9->SetRenderState(D3DRS_ZENABLE, true);}CRenderCanvas::~CRenderCanvas(){}void CRenderCanvas::onPaint( wxPaintEvent& WXUNUSED(event) ){wxPaintDC dc(this);}void CRenderCanvas::onSize(wxSizeEvent& event){wxSize newSize = GetSize();m_PresentParams.BackBufferWidth= newSize.x;m_PresentParams.BackBufferHeight = newSize.y;m_lpSprite->OnLostDevice();m_lpDirect3DDevice9->Reset(&m_PresentParams);m_lpSprite->OnResetDevice();}void CRenderCanvas::Render(){m_lpDirect3DDevice9->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , D3DCOLOR_XRGB(0, 128, 0), 1, 0);if (m_lpDirect3DDevice9->TestCooperativeLevel() == D3DERR_DEVICENOTRESET){m_lpSprite->OnLostDevice();m_lpDirect3DDevice9->Reset(&m_PresentParams);m_lpSprite->OnResetDevice();}m_lpDirect3DDevice9->BeginScene();m_lpSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT);m_lpSprite->End();m_lpDirect3DDevice9->EndScene();m_lpDirect3DDevice9->Present(NULL, NULL, NULL, NULL);}Also, I create the RenderCanvas in an object of the wxFrame, so the RenderCanvas is called upon this waym_pRenderCanvas  = new CRenderCanvas(this, wxID_ANY);HWND hWnd = (HWND)m_pRenderCanvas->GetHWND();m_pRenderCanvas->BuildD3D(hWnd, size.x, size.y);The render canvas onSize is called by thisvoid CMyFrame::OnResize(wxSizeEvent &event){wxSize clientSize = GetClientSize();if(m_pRenderCanvas != NULL){m_pRenderCanvas->SetSize(clientSize);m_pRenderCanvas->Refresh();IDirect3DVertexBuffer9 *pDirectXVB;m_pRenderCanvas->m_lpDirect3DDevice9->CreateVertexBuffer(4*12, 0, 0, D3DPOOL_DEFAULT, &pDirectXVB, 0);}}Does anyone happen to know what the issue may be ?   
  You're not checking the return value of IDirect3DDevice9::Reset, which means it may be failing and you wouldn't know. Same goes for a other D3D calls. I would add some checks in there, and also enable the debug runtimes if you haven't already. The debug runtimes will output messages telling you more about why a call failed.Also be aware that any resources created in D3DPOOL_DEFAULT will need to be destroyed before you can call Reset.   ;  I am running it in debug and checking all the hr results, if there is something else I could be doing then could you please explain?   ;Quote:Original post by HurpI am running it in debugDo you mean running your debug build? I'm talking about activating the debug runtimes from the DirectX Control Panel.;  What I wanted to say was the debug version on my build, but yes, I had Debug (not Retail) in my DirectX Control Panel set on. Also, I was looking at the error code of $err,hr in the watch window, not knowing it did not work for directx calls. Upon looking at it when the Reset(params) gets called after the resize I get the hr of -2005530516 (D3DERR_INVALIDCALL) which says the methods call is invalid. However, I am not sure how it can be invalid.The call is just "m_lpDirect3DDevice9->Reset(&m_PresentParams)", looked at the values of m_PresentParams while debugging any the still look valid. The memory address is also the same as when the program started.I thought maybe it was the setting of the BackBufferWidth and BackBufferHeight that was causing it to be invalid, but even when I commented those assignments out I still get the error.   ;  It sounds like something didn't get Released properly, like MJP said.  Did you release any vertex buffer(s) you created before you tried to Reset the device?   ;Quote:Original post by AmrazekIt sounds like something didn't get Released properly, like MJP said.  Did you release any vertex buffer(s) you created before you tried to Reset the device?I do not create the vertex buffer until after I reset the device, I don't think anything should be getting released, all I make is the devices.   ;  I am still trying to resolve this issue, however, I have hit a wall. I know the HR result from the device-> Reset is -2005530516 ( D3DERR_INVALIDCALL ) but I just do not know how. Does anyone know how?   ;  When I test the cooperative level before I set the device it returns an S_OK. However, seeing as how the size of the window changed, shouldn't that be something other than S_OK?Basically, I want to change the width and height of the back buffer in the presentation params because the size of the window changed, is this necessary?Here is what I currently do when resizing a window{m_PresentParams.BackBufferWidth= width;m_PresentParams.BackBufferHeight = height;HRESULT hr = m_lpDirect3DDevice9->TestCooperativeLevel();// hr result is S_OK nowhr = m_lpDirect3DDevice9->Reset(&m_PresentParams);// hr result is -2005530516 now }   ;  what kind of library is wxwidgets   