Hi everyone
My name TPham, I am a Game Dev
I have a problem for using multithreading in my project.
I make a function from multihreading to show image “loading data” while the app is loading total data for game lesson.
But, the image “loading data” was not shown.
I run my project on windows, the image is show
But on Android studio. the image is not shown
My Code:
The Init Function:
bool GameMain::LoadData()
{
DataGame* dataGame = new DataGame();
dataGame->sWidth = m_ScreenWidth;
dataGame->sHeight = m_ScreenHeight;
dataGame->screen = m_Screen;
SDL_Thread* threadID = SDL_CreateThread(LoadingFunction, "LoadingThread", (void*)dataGame);
LoadTexture();
InitLesson1();
InitLesson2();
InitLesson3();
InitLesson4();
InitEndLesson();
g_Finished = true; // global variable
return true;
}
The Thread Function
int LoadingFunction(void* data_game)
{
DataGame* dataGame = (DataGame*)data_game;
if (dataGame != NULL)
{
DataResize data_resize{ dataGame->sWidth, dataGame->sHeight, true };
BaseObject bkgnObj;
bkgnObj.SetIsBackGround(true);
bkgnObj.SetScreenSize(dataGame->sWidth, dataGame->sHeight);
bkgnObj.SetDataResize(data_resize);
bool ret = bkgnObj.LoadImg("bkgn_loading.png", dataGame->screen);
bkgnObj.SetRect(0, 0);
while (!g_Finished)
{
SDL_SetRenderDrawColor(dataGame->screen, RENDER_DRAW_COLOR,..);
SDL_RenderClear(dataGame->screen);
bkgnObj.RenderBkgn(dataGame->screen);
SDL_RenderPresent(dataGame->screen);
}
}
return 0;
}
I want to get help from everyone. Thank you so much.