From 3c007bf3b2f6b398df4fc29cfa1ecfe0e4639907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Devernay?= Date: Wed, 25 Jul 2018 09:25:49 +0200 Subject: [PATCH] LensDistortion: fix reading PFBarrel files fixes https://github.com/NatronGitHub/Natron/issues/296 --- Distortion/Distortion.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Distortion/Distortion.cpp b/Distortion/Distortion.cpp index ec896590c..4e70e3e76 100644 --- a/Distortion/Distortion.cpp +++ b/Distortion/Distortion.cpp @@ -604,7 +604,7 @@ PFBarrelCommon::FileReader::FileReader(const std::string &filename) } else if (ln=="#PFBarrel 2011 v2") { version_= 2; } else { - error_= "Bad header"; + error_= "Bad header: " + ln; return; } @@ -697,11 +697,12 @@ std::string PFBarrelCommon::FileReader::readRawLine(void) char* s = std::fgets(buf, sizeof(buf) - 1, f_); if (s != NULL) { rv= s; - rv= rv.erase(rv.length()-1); + // trim \r and \n from the end of line + while (!rv.empty() && (rv[rv.size() - 1] == '\r' || rv[rv.size() - 1] == '\n')) + rv.erase(rv.size() - 1); } else { error_= "Parse error"; } - return rv; } @@ -3257,8 +3258,13 @@ DistortionPlugin::changedParam(const InstanceChangedArgs &args, } else if ( (paramName == kParamPFFileReload) || ( (paramName == kParamPFFile) && (args.reason == eChangeUserEdit) ) ) { std::string filename; + _pfFile->getValueAtTime(args.time, filename); PFBarrelCommon::FileReader f(filename); - + if ( !f.error_.empty() ) { + // no persistent message, since this is triggered by a used action + sendMessage(Message::eMessageError, "", "Error reading file \"" + filename + "\": " + f.error_); + throwSuiteStatusException(kOfxStatFailed); + } beginEditBlock(kParamPFFile); _pfC3->deleteAllKeys(); _pfC5->deleteAllKeys();