0x00EB18E0 处有未经处理的错误(在 EngineW32.exe 中): 0xC0000005: 写入位置 0x00000010 时发生访问冲突

0x00EB18E0 处有未经处理的异常(在 EngineW32.exe 中): 0xC0000005: 写入位置 0x00000010 时发生访问冲突
这个本来在一个cpp里面是可以的 但是封装到类里面就不行了 不知道怎么回事 运行就给这个

0x00EB18E0 处有未经处理的异常(在 EngineW32.exe 中): 0xC0000005: 写入位置 0x00000010 时发生访问冲突

uiClientHeight = r.bottom - r.top;
01321707  mov         eax,dword ptr [ebp-50h]  
0132170A  sub         eax,dword ptr [ebp-58h]  
0132170D  mov         ecx,dword ptr [this]  
01321710  mov         dword ptr [ecx+0Ch],eax  就这给停了


纠结了好久啊 有人能告诉我怎么回事吗?

SystemClass.cpp
#include "SystemClass.h"


SystemClass::SystemClass(void)
{
m_hInstance = 0;
m_hWnd = 0;
/*
m_pd3dDevice = 0;
m_pImmediateContext = 0;
m_pRenderTargetView = 0;
m_pSwapChain = 0;
m_driverType = D3D_DRIVER_TYPE_NULL;
m_featureLevel = D3D_FEATURE_LEVEL_11_0;
*/

}


SystemClass::~SystemClass(void)
{
}

HRESULT SystemClass::InitializeWindow(HINSTANCE hInstance,int nShowCmd)
{
WNDCLASSEX wcex ={
sizeof(WNDCLASSEX),
CS_HREDRAW | CS_VREDRAW | CS_OWNDC,
MsgProc,
0,
0,
hInstance,
LoadIcon(0,IDI_APPLICATION),
LoadCursor(0,IDC_ARROW),
(HBRUSH)GetStockObject(WHITE_BRUSH),
0,
"Engine",
LoadIcon(0,IDI_APPLICATION)
};

if (!RegisterClassEx(&wcex))
{
MessageBox(0,"Failed to register class",0,0);
return S_FALSE;
}

RECT r;
r.bottom = 600;
r.left = 0;
r.right = 600;
r.top = 0;

AdjustWindowRect(&r,WS_OVERLAPPEDWINDOW,false);
uiClientHeight = r.bottom - r.top;
uiClientWidth = r.right - r.left;
m_hWnd = CreateWindow("Engine","Engine",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,uiClientWidth,uiClientHeight,0,0,wcex.hInstance,0);
if (!m_hWnd)
{
return S_FALSE;
}
ShowWindow(m_hWnd,nShowCmd);

return S_OK;
}

HRESULT SystemClass::InitD3D(HWND hFocusWindow)
{
return S_OK;
}

void SystemClass::Render()
{

}

int SystemClass::Run()
{
MSG msg;
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Render();
}
}
return static_cast<int>(msg.wParam);
}

LRESULT SystemClass::WndProc(HWND hWnd,UINT msg, WPARAM wParam,LPARAM lParam)
{
return DefWindowProc(hWnd,msg,wParam,lParam);
}

void SystemClass::Release()
{
/*
m_pd3dDevice->Release();
m_pd3dDevice = 0;

m_pImmediateContext->Release();
m_pImmediateContext = 0;

m_pRenderTargetView->Release();
m_pRenderTargetView = 0;

m_pSwapChain->Release();
m_pSwapChain = 0;
*/
}

LRESULT CALLBACK MsgProc(HWND hWnd, UINT msg , WPARAM wParam , LPARAM lParam)
{
return pApplication->WndProc(hWnd,msg,wParam,lParam);
}



main.cpp
#include "SystemClass.h"

int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd )
{
SystemClass * pSystem = 0;
if (FAILED(pSystem->InitializeWindow(hInstance,nShowCmd)))
{
return 1;
}

pSystem->Run();

return 0;
}

------解决方案--------------------
SystemClass * pSystem = 0;

if (FAILED(pSystem->InitializeWindow(hInstance,nShowCmd)))
//...

pSystem->Run();

//你将pSystem  = NULL,后面又使用他,不崩溃才怪...

你先SystemClass * pSystem = new SystemClass ;
然后再用
------解决方案--------------------
SystemClass * pSystem = 0;