Exemplo n.º 1
0
void
clean_struct (struct ALL_DATA *all_data) 
{
	struct GWIDGET *gwidget = all_data->gwidget;
	struct VidState *s = all_data->s;
	struct paRecordData *pdata = all_data->pdata;
	struct GLOBAL *global = all_data->global;
	struct focusData *AFdata = all_data->AFdata;
	struct vdIn *videoIn = all_data->videoIn;
	struct VideoFormatData *videoF = all_data->videoF;
	
	gboolean control_only = (global->control_only || global->add_ctrls);
	if((!control_only) && (pdata != NULL))
	{
		/*destroy mutex for sound buffers*/
		if (global->debug) g_printf("free audio mutex\n");
		g_mutex_free( pdata->mutex );

		g_free(pdata);
		pdata=NULL;
		all_data->pdata=NULL;
		g_free(videoF);
		videoF=NULL;
	}
	
	if(videoIn) close_v4l2(videoIn, control_only);
	videoIn=NULL;
	if (global->debug) g_printf("closed v4l2 strutures\n");

	

	if (s->control_list) 
	{
		free_control_list (s->control_list);
		s->control_list = NULL;
		g_printf("free controls\n");
	}
	g_free(s);
	s = NULL;
	all_data->s = NULL;

	g_free(gwidget);
	gwidget = NULL;
	all_data->gwidget = NULL;

	if (global->debug) g_printf("free controls - vidState\n");

	g_free(AFdata);
	AFdata = NULL;
	all_data->AFdata = NULL;

	if(global) closeGlobals(global);
	global=NULL;
	all_data->global=NULL;

	g_printf("cleaned allocations - 100%%\n");
}
Exemplo n.º 2
0
int main( int argc, char* args[] )
{
	element_cntrl pressed_Button=NULL; 
	SDL_Event test_event; 
	int pause=0,error;

	gui_init();
	error=go_to_start_menu(&pause,&test_event);
	if (error<0 || cur_game==NULL){
		if (quit==1){
			free_control_list(ui_tree);
			if (cur_game!=NULL)
			{
				free(cur_game->board);
				free(cur_game);
			}
		}
		TTF_Quit();
		SDL_Quit();
		return 0;
	}
	while(!quit)
    {
		while(SDL_PollEvent(&test_event)) {
			if(test_event.type == SDL_QUIT){
				quit=1;
				break;
			}
			switch(test_event.type) {
			case SDL_MOUSEBUTTONDOWN:
				find_element_by_coordinates(ui_tree,test_event.button.x,test_event.button.y,&pressed_Button);
				if(pressed_Button==NULL)
				{
					 break;
				}
				error=pressed_Button->cntrl->pressed_button(&pause,&test_event);
				if (error<0 ||cur_game==NULL){
					printf("a catchAble error occured\n");
					TTF_Quit();
					SDL_Quit();
					return 0;
				}
				break;
			default: //unhandled event
				break;
			}
			if (cur_game!=NULL && cur_game->is_multiplayer==1 && pause==0){
				error=handelAI_VS_AI(&pause);
				if (error<0 ||cur_game==NULL){
					printf("a catchAble error occured\n");
					free_control_list(ui_tree);
					if (cur_game!=NULL)
					{
						free(cur_game->board);
						free(cur_game);
				}
				TTF_Quit();
				SDL_Quit();
				return 0;
				}
			}
		}
	}
	free_control_list(ui_tree);
	if (cur_game!=NULL)
	{
		free(cur_game->board);
		free(cur_game);
	}
	TTF_Quit();
	SDL_Quit();
	return 0;
}