在 DirectX 9.0 中以后台模式加载资源

发布于 2024-12-11 17:11:22 字数 1813 浏览 0 评论 0原文

我用DirectX9.0制作了一个3D游戏。

我想通过使用线程在后台模式下加载资源。

这是我的代码。

----------------Attakc.h----------------------------------------

#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----------------------------------------

...

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)

我认为这与线程的同步有关。

我没有通过使用线程加载资源的经验。

请帮我。

I have made an 3D Game with DirectX9.0.

I want to load resources in background mode by use thread.

Here is my code.

----------------Attakc.h---------------------------

#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---------------------------

...

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;
}

Then, When I run this project, E_OUTOFMEMORY error appear.(D3DXCreateTextureFromFile)

I think it belong about the thread's synchronization.

I have no experience to load resource by use thread.

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别想她 2024-12-18 17:11:22

初始化 d3d 时是否使用了 D3DCREATE_MULTITHREADED 标志?

Did you used D3DCREATE_MULTITHREADED flag when initializing d3d?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文