diff core/default_libpd_render.cpp @ 470:5a936f8e9447 prerelease

I mean it actually works for real. Libpd checks for file and exits with meaningful error message if it does not find it.
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 20 Jun 2016 18:04:11 +0100
parents 03a2cd5f151b
children efc9a9f8e63d
line wrap: on
line diff
--- a/core/default_libpd_render.cpp	Mon Jun 20 17:08:02 2016 +0100
+++ b/core/default_libpd_render.cpp	Mon Jun 20 18:04:11 2016 +0100
@@ -127,6 +127,16 @@
 
 bool setup(BelaContext *context, void *userData)
 {
+	// Check first of all if file exists. Will actually open it later.
+	char file[] = "_main.pd";
+	char folder[] = "./";
+	unsigned int strSize = strlen(file) + strlen(folder) + 1;
+	char* str = (char*)malloc(sizeof(char) * strSize);
+	snprintf(str, strSize, "%s%s", folder, file);
+	if(access(str, F_OK) == -1 ) {
+		printf("Error file %s/%s not found. The %s file should be your main patch.\n", folder, file, file);
+		return false;
+	}
 	dcm.setCallback(sendDigitalMessage);
 	analogChannelsInUse = min(context->analogChannels, gChannelsInUse - context->audioChannels - context->digitalChannels);
 	if(context->digitalChannels > 0){
@@ -189,10 +199,12 @@
 	libpd_bind("bela_digitalOut26");
 	libpd_bind("bela_setDigital");
 
-	char file[] = "_main.pd";
-	char folder[] = "./";
 	// open patch       [; pd open file folder(
-	libpd_openfile(file, folder);
+	void* patch = libpd_openfile(file, folder);
+	if(patch == NULL){
+		printf("Error: file %s/%s is corrupted.\n", folder, file); 
+		return false;
+	}
 	libpdReadFilesTask = Bela_createAuxiliaryTask(libpdReadFilesLoop, 60, "libpdReadFiles");
 	Bela_scheduleAuxiliaryTask(libpdReadFilesTask);