From 9943c9f8b7067d3cd1354b24cc4ee85082646d90 Mon Sep 17 00:00:00 2001
From: Andrew Randrianasulu <randrianasulu@gmail.com>
Date: Tue, 12 Oct 2021 11:17:51 +0300
Subject: [PATCH 1/3] Attempt at fixing mwindow->appimageDir = NULL

---
 cinelerra-5.1/cinelerra/mwindow.C | 15 ++++++++++++---
 cinelerra-5.1/cinelerra/mwindow.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C
index 2a86aaae..b3a12239 100644
--- a/cinelerra-5.1/cinelerra/mwindow.C
+++ b/cinelerra-5.1/cinelerra/mwindow.C
@@ -240,7 +240,7 @@ MWindow::MWindow()
 	sighandler = 0;
 	restart_status = 0;
 	screens = 1;
-	appimageDir = getenv("APPDIR"); //NULL if not running as appimage
+	appimageDir = getenv("APPDIR"); //NULL if not running as appimage 
 	in_destructor = 0;
 	speed_edl = 0;
 	beeper = 0;
@@ -675,6 +675,15 @@ int MWindow::check_plugin_index(ArrayList<PluginServer*> &plugins,
 	}
 	return 0;
 }
+
+int MWindow::is_appimage()
+{
+	if (getenv("APPDIR"))
+	return 1;
+    return 0;
+}
+
+
 /*
 * @brief Load built-in and LV2 plugins as specified in index file,
 *        rebuild the index file if needed.
@@ -691,7 +700,7 @@ int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
 	// index_id is 2nd line of the index file, normally full plugin path,
 	// but fixed value if AppImage because the path changes on each run.
 	// And if the second line does not match on the next run the index is rebuilt.
-	if( mwindow->appimageDir ) strcpy(index_id, getenv("CINGG_BUILD"));
+	if( mwindow->is_appimage() && getenv("CINGG_BUILD")) strcpy(index_id, getenv("CINGG_BUILD"));
 	else strcpy(index_id, plugin_path);
 	FILE *fp = fopen(index_path,"a+");
 	if( !fp ) {
@@ -751,7 +760,7 @@ int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
 		// If the first part of the plugin_path matches the APPDIR, we are
 		// referring to CinGG's ladspa, replace the path by a fixed ID. APPDIR
 		// only exists if we are running as AppImage (with variable mount points).
-		if( mwindow->appimageDir && strncmp(plugin_path, mwindow->appimageDir, strlen(mwindow->appimageDir)) == 0 )
+		if( mwindow->is_appimage() && strncmp(plugin_path, mwindow->appimageDir, strlen(mwindow->appimageDir)) == 0 )
 			strcpy(index_id, getenv("CINGG_BUILD"));
 		else strcpy(index_id, plugin_path);
 
diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h
index 46e96643..ed20bfbd 100644
--- a/cinelerra-5.1/cinelerra/mwindow.h
+++ b/cinelerra-5.1/cinelerra/mwindow.h
@@ -859,6 +859,7 @@ public:
 	int restart_status;
 	int screens;
 	const char *appimageDir;
+	int is_appimage();
 	int in_destructor;
 	Shuttle *shuttle;
 	WinTV *wintv;
-- 
2.33.0

