Hi,

Using Hugin 2017.0 (and prior versions), if one tries to stitch a project 
where there are non-ascii characters in the project's file path the 
stitching fails. This is related to bug 
https://bugs.launchpad.net/hugin/+bug/678808 and its duplicates.
After some debugging it turns out that the culprit is the call to 
hugin_stich_project using wxExecute. wxExcute does a poor (buggy) handling 
of converting the internal Unicode representation to UTF-8 and drops any 
arguments containing non-ascii characters. The attached bug works around 
it, and solves the issue.

I've tested it on Debian Stretch. It should probably be tested on other 
platforms as well, or alternatively, I can change the patch to only affect 
wxGTK.

Thanks,
Guy
https://www.guyrutenberg.com/

-- 
A list of frequently asked questions is available at: 
http://wiki.panotools.org/Hugin_FAQ
--- 
You received this message because you are subscribed to the Google Groups 
"hugin and other free panoramic software" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/hugin-ptx/afcb295e-660a-462c-9202-bd7697f7e9fc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>From a82fdbe74c05fd392f6cb771c12a5f315397975b Mon Sep 17 00:00:00 2001
From: Guy Rutenberg <[email protected]>
Date: Sat, 23 Sep 2017 18:55:35 +0300
Subject: [PATCH] Fix handling on non-ascii paths when stitching.

This solves bug #678808, by working around a bug in the handling of
non-ascii characters in wxExecute.
---
 src/hugin1/hugin/PanoPanel.cpp | 36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/hugin1/hugin/PanoPanel.cpp b/src/hugin1/hugin/PanoPanel.cpp
index e014aa4..37588d1 100755
--- a/src/hugin1/hugin/PanoPanel.cpp
+++ b/src/hugin1/hugin/PanoPanel.cpp
@@ -1179,11 +1179,25 @@ void PanoPanel::DoStitch()
         return;
     };
 
-    wxString switches(wxT(" --delete -o "));
-    if(wxConfigBase::Get()->Read(wxT("/Processor/overwrite"), HUGIN_PROCESSOR_OVERWRITE) == 1)
-        switches=wxT(" --overwrite")+switches;
-    wxString command = hugin_stitch_project + switches + hugin_utils::wxQuoteFilename(dlg.GetPath()) + wxT(" ") + hugin_utils::wxQuoteFilename(currentPTOfn);
-    
+    // wxExecute(wxString, ...) is broken because it drops any non-ascii
+    // arguments. To work around it, at least until it is fixed by wxwidgets,
+    // we should split the arguments ourselves. In any case, it is a better
+    // practice as we can avoid doing unnecessary quoting (as wxWidgets has
+    // to unquote it anyway when it splits it to separate arguments).
+    std::vector<wxChar *> argv;
+    argv.push_back(wxStrdup(hugin_stitch_project.wx_str()));
+    if (wxConfigBase::Get()->Read(wxT("/Processor/overwrite"), HUGIN_PROCESSOR_OVERWRITE) == 1) {
+        argv.push_back(wxStrdup(wxT("--overwrite")));
+    }
+    argv.push_back(wxStrdup(wxT("--delete")));
+    argv.push_back(wxStrdup(wxT("-o")));
+
+    // no need to quote the filenames, as each is in its own argument.
+    argv.push_back(wxStrdup(dlg.GetPath().wx_str()));
+    argv.push_back(wxStrdup(currentPTOfn.wx_str()));
+
+    argv.push_back(NULL);
+
     wxConfigBase::Get()->Flush();
 #ifdef __WXGTK__
     // work around a wxExecute bug/problem
@@ -1193,10 +1207,18 @@ void PanoPanel::DoStitch()
 
     // Delete itself once processes terminated.
     my_process->Detach();
-    wxExecute(command,wxEXEC_ASYNC, my_process);
+    wxExecute(&argv[0], wxEXEC_ASYNC, my_process);
+
 #else
-    wxExecute(command);
+    wxExecute(&argv[0]);
 #endif
+    // free up all the strdup'ed strings
+    for (size_t i = 0; i < argv.size(); i++) {
+        if (argv[i]) {
+            free(argv[i]);
+        }
+    }
+
     HuginBase::LensDB::SaveLensDataFromPano(*pano);
 }
 
-- 
2.11.0

Reply via email to