Jump to content
  • Advertisement
Sign in to follow this  

SDL multithreading and multicore issue

This topic is 2255 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've been met wit an interesting problem.
First of all, I'd like to say I successfully rolled out my first game framework, which has been my goal for quite some time. Now if I do want to make a game, I can choose a mature engine with no regret.

(Sure there are problems, but as long as it works on my PC, I'm happy :D)

Anyway, my problem is as follows.
I'm using lua as a script engine. So I exposed a showMsg API to show text on the screen.

So in my script, it runs multiple showMsg commands

They don't seem to be blocking so the text would overlap, which was the reason why I introduced SDL_SemWait and SDL_SemPost

Here's the function that is registered to be called by lua

int l_showMSG(lua_State *l)
//need a messagebox class
//messagebox class will use a list to contain the messages
//showMSG should be added to the list
#ifndef _DEBUG
char* fontname = (char*) lua_tostring(mainL,-1); lua_pop(mainL,1);
wchar_t* txt = (wchar_t *) lua_tostring(mainL,-1);
// char* ctxt = (char*) lua_tostring(mainL,-1);

std::wstringstream buf;
buf << txt;

int x = 30;
int y = 30;
if (lua_gettop(mainL)>0)
y = lua_tonumber(mainL,-1);lua_pop(mainL,1);
x = lua_tonumber(mainL,-1);lua_pop(mainL,1);
//wstring msg = buf.str();
//wstring drawmsg = processWide(*msg);
#ifndef _DEBUG
printf("showMSG::before RenderText\n");
// delete msg;
//delete msg;
return 0;

This works perfectly fine on my dual core Lenovo, but when I send it to other people. They sometime would see two showMsg calls overlapping.

So my hunch is still that the two lua calls each obtained the lock and both executed the drawtext code.
I'm wondering if it would be due to multicore multi-cache, and if it is so, how would I proceed to fix it?

Thank you

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!