一个SDL的问题

游戏讨论
回复
CStick
帖子: 21
注册时间: 2008-06-09 11:57

一个SDL的问题

#1

帖子 CStick » 2009-06-16 0:54

高手们帮我解释一下,我在一个线程里面生成了一个surface 然后用另一个线程 blitsurface 然后就SIGSEGV 为什么啊~~
难道不能够这样 ,解决的办法是?
小弟多谢各位了~

代码: 全选

#include <SDL.h>
#include <SDL_ttf.h>
#include <SDL_thread.h>
SDL_Surface* disp;
TTF_Font* font;
SDL_Thread* thread;
SDL_Surface* text;
int proc( void * parm)
{
	SDL_Color color = {255,255,255};
	text = TTF_RenderText_Solid( font , "test" , color );
	while(1);	
}
int main()
{
	SDL_Init(SDL_INIT_VIDEO);
	TTF_Init();
	disp = SDL_SetVideoMode(800,600,32,SDL_SWSURFACE);
	font = TTF_OpenFont("font.ttf",15);
	thread = SDL_CreateThread(proc ,NULL );
	while(1)
	{
		if(text)
		{
			SDL_BlitSurface( text , NULL , disp , NULL );
			text = NULL;
		}
	}
	return 0;
}
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

Re: 一个SDL的问题

#2

帖子 fuhuizn » 2009-06-16 16:24

用线程互斥保证同一时间只有一个线程操作surface
回复