Procházet zdrojové kódy

text-freetype2: Fix issues with text file loading

jp9000 před 11 roky
rodič
revize
93d9317b7d

+ 14 - 20
plugins/text-freetype2/text-freetype2.c

@@ -295,13 +295,6 @@ static void ft2_source_update(void *data, obs_data_t settings)
 
 	if (ft2_lib == NULL) return;
 
-	if (!from_file) {
-		if (srcdata->text_file != NULL) {
-			bfree(srcdata->text_file);
-			srcdata->text_file = NULL;
-		}
-	}
-
 	if (srcdata->draw_effect == NULL) {
 		char *effect_file = NULL;
 		char *error_string = NULL;
@@ -321,9 +314,12 @@ static void ft2_source_update(void *data, obs_data_t settings)
 		}
 	}
 
-	if (srcdata->font_size != font_size)
+	if (srcdata->font_size != font_size ||
+	    srcdata->from_file != from_file)
 		vbuf_needs_update = true;
 
+	srcdata->from_file = from_file;
+
 	if (srcdata->font_name != NULL) {
 		if (strcmp(font_name,  srcdata->font_name)  == 0 &&
 		    strcmp(font_style, srcdata->font_style) == 0 &&
@@ -363,22 +359,20 @@ static void ft2_source_update(void *data, obs_data_t settings)
 skip_font_load:;
 	if (from_file) {
 		const char *tmp = obs_data_get_string(settings, "text_file");
-		if (strlen(tmp) == 0)
-			return;
-		if (srcdata->text_file != NULL) {
-			if (strcmp(srcdata->text_file, tmp) == 0
-				&& !vbuf_needs_update)
-				goto error;
-			bfree(srcdata->text_file);
-			srcdata->text_file = NULL;
-		}
-		else {
+		if (!tmp || !*tmp) {
 			blog(LOG_WARNING,
 				"FT2-text: Failed to open %s for reading", tmp);
 			goto error;
 		}
-		srcdata->text_file = bstrdup(tmp);
 
+		if (srcdata->text_file != NULL &&
+		    strcmp(srcdata->text_file, tmp) == 0 &&
+		    !vbuf_needs_update)
+			goto error;
+
+		bfree(srcdata->text_file);
+
+		srcdata->text_file = bstrdup(tmp);
 		if (chat_log_mode)
 			read_from_end(srcdata, tmp);
 		else
@@ -387,7 +381,7 @@ skip_font_load:;
 	}
 	else {
 		const char *tmp = obs_data_get_string(settings, "text");
-		if (strlen(tmp) == 0) goto error;
+		if (!tmp || !*tmp) goto error;
 
 		if (srcdata->text != NULL) {
 			bfree(srcdata->text);

+ 1 - 0
plugins/text-freetype2/text-freetype2.h

@@ -33,6 +33,7 @@ struct ft2_source {
 	uint16_t font_size;
 	uint32_t font_flags;
 
+	bool from_file;
 	char *text_file;
 	wchar_t *text;
 	time_t m_timestamp;