我用DirectX9.0制作了3D游戏。
我想通过使用线程在后台模式下加载资源。
这是我的代码。
---------------- Attakc.h --------------------------- < / p>
#define AFXBEGINTHREAD(pfnThreadProc,pParam) AfxBeginThread(pfnThreadProc, pParam, THREAD_PRIORITY_NORMAL,0,CREATE_SUSPENDED,NULL)
CWinThread* g_pThread = NULL;
volatile bool g_bExitThread = true;
CCriticalSection g_csExitThread;
---------------- Attakc.cpp --------------------------- < / p>
...
case WM_START:
if(wParam >= 0 && wParam < 18)
{
g_csExitThread.Lock();
g_bExitThread = false;
g_csExitThread.Unlock();
g_pThread = AFXBEGINTHREAD(ThreadFunc,0);
if(NULL == g_pThread)
{
MessageBoxW(0,L"Failed to Create Thread",0,0);
}
g_pThread->m_bAutoDelete = TRUE;
g_pThread->ResumeThread();
wParamTemp = wParam;
lParamTemp = lParam;
uMsgTemp = uMsg;
}
...
UINT ThreadFunc(LPVOID lpParam)
{
while(true)
{
Sleep(1);
g_csExitThread.Lock();
if(true == g_bExitThread)
{
g_csExitThread.Unlock();
break;
}
else
{
g_csExitThread.Unlock();
g_pApp->GotoHole(wParamTemp, lParamTemp);
g_bExitThread = true;
g_pApp->m_nRenderMode = RENDERMODE_SCENE;
g_pApp->StartFlyOver();
g_pApp->m_flyOver.bFirstTime = TRUE;
g_pApp->m_uiLoadingMenu.m_bStart = FALSE;
g_pApp->m_uiLoadingMenu.nTime = 0;
g_pApp->m_uiLoadingMenu.count = 0;
}
}
return 0L;
}
然后,当我运行此项目时,出现E_OUTOFMEMORY错误。(D3DXCreateTextureFromFile)
我认为它属于线程的同步。
我没有使用线程加载资源的经验。
请帮帮我。
答案 0 :(得分:0)
初始化d3d时是否使用过D3DCREATE_MULTITHREADED标志?