Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problem in Multithreaded rendering

Started by idreamlovey Apr 3, 2007 at 2:15 PM 4 replies 1.3k views
Original Post
idreamlovey
idreamlovey
I am using one thread to load the game data and another thread to render the current loading by rendering splash with progress bar.The problem is data loading is working but i can't see any splash rendering. Even not a single time splash appears on the screen. I m new with multithreading. The following is my code:- //Start of Code HANDLE hThrd1,hThrd2; hThrd1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LoadMenuObjects, this, CREATE_SUSPENDED, NULL); ResumeThread(hThrd1); SetThreadPriority(hThrd1,THREAD_PRIORITY_HIGHEST); // Run the secound Thread hThrd2 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)RenderLoadingPage, this, CREATE_SUSPENDED, NULL); ResumeThread(hThrd2); SetThreadPriority(hThrd1,THREAD_PRIORITY_LOWEST); UINT LoadMenuObjects(LPVOID lpvoid) { CMyGame *vPt = (CMyGame *)lpvoid; vPt->nGlobalMax = 38; vPt->nGlobalCt = 1; vPt->ConstructMenuObjects(0); vPt->RestoreMenuObjects(0); vPt->ConstructEngineObjects(); vPt->RestoreEngineObjects(); vPt->m_dwAppState = APPSTATE_RESET_TIME2; return 0; } UINT RenderLoadingPage(LPVOID lpvoid) { COvertake *vPt = (COvertake *)lpvoid; while(vPt->m_dwAppState != APPSTATE_RESET_TIME2) { vPt->RenderSplashObjects(1,vPt->nGlobalCt,vPt->nGlobalMax); break; } return 0; } //End of Code
Uziel2101
Uziel2101
vPt->m_dwAppState = APPSTATE_RESET_TIME2;


while(vPt->m_dwAppState != APPSTATE_RESET_TIME2)

isn't it supposed to be ==

this is just a quick glance, will get back to it when I get back from lunch
Uziel was defeated by Tiny Mandragora.
Evil Steve
Evil Steve
And what do the debug runtimes tell you? Does it work when it's single-threaded?
idreamlovey
idreamlovey
Previously vPt->m_dwAppState is set to APPSTATE_LOAD_GAME so here the loop while is working fine but yes it does slows the loading and thats why i put break there in the next line.
In single threaded, i called loading and render functions alternately and it works fine but when i call them as follows
LoadMenuObjects(this);
RenderLoadingPage(this);
it doesn't works and i test whether it really executing the render function by
UINT RenderLoadingPage(LPVOID lpvoid)
{
CMyGame *vPt = (CMyGame *)lpvoid;
vPt->RenderSplashObjects(1,vPt->nGlobalCt,vPt->nGlobalMax);
vPt->RenderSplashObjects(1,vPt->nGlobalCt,vPt->nGlobalMax);
vPt->RenderSplashObjects(1,vPt->nGlobalCt,vPt->nGlobalMax);
vPt->RenderSplashObjects(1,vPt->nGlobalCt,vPt->nGlobalMax);
/*while(vPt->m_dwAppState != APPSTATE_RESET_TIME4&&vPt->m_dwAppState != APPSTATE_RESET_TIME2)
{
vPt->RenderSplashObjects(1,vPt->nGlobalCt,vPt->nGlobalMax);
}*/
return 0;
}
and it comes out that it is executing but does not appears on the screen.
idreamlovey
idreamlovey
i am using directx and already set the option D3DCREATE_MULTITHREADED at the creation time. I also tried remove the priority option and i set rendering function in main thread and the code becomes like as below:-

if(m_bIsLoading==false)
{
m_bIsLoading = true;
HANDLE hThrd1;
hThrd1 = CreateThread(NULL, 0,(LPTHREAD_START_ROUTINE) LoadMenuObjects,
this, CREATE_SUSPENDED, NULL);
}
RenderSplashObjects(1,nGlobalCt,nGlobalMax);
and it appears RenderSplashObjects() function has been executed 13878 times. And it still nothing appears on the screen.
idreamlovey
idreamlovey
Problem is solved its not problem in my coding the only thing that i missed is i haven't put the line
g_pd3dDevice->Present( 0, 0, 0, 0 );

Thanks a lot u guys.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.