Sign in to follow this  

SDL multithreading and multicore issue

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this