From 00a7eb89b3af29152c055d18089e50a87d01aa78 Mon Sep 17 00:00:00 2001 From: Persune Date: Tue, 12 Dec 2023 15:42:30 +0800 Subject: [PATCH] Avoid printing in empty JSON block text export --- Source/SoundGen.cpp | 2 +- Source/TextExporter.cpp | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Source/SoundGen.cpp b/Source/SoundGen.cpp index e2fb61cf..bc64a275 100644 --- a/Source/SoundGen.cpp +++ b/Source/SoundGen.cpp @@ -2450,7 +2450,7 @@ void CSoundGen::UpdateAPU() UpdateAPU(); l.unlock(); } - else TRACE("SoundGen: APU mutex lock failed"); + else TRACE("SoundGen: APU mutex lock failed\n"); } } diff --git a/Source/TextExporter.cpp b/Source/TextExporter.cpp index 215b2f9f..809be8cd 100644 --- a/Source/TextExporter.cpp +++ b/Source/TextExporter.cpp @@ -1743,16 +1743,18 @@ const CString& CTextExport::ExportFile(LPCTSTR FileName, CFamiTrackerDoc *pDoc) f.WriteString(_T("# JSON block\n")); { json j = pDoc->InterfaceToOptionalJSON(); - std::string &jsondump = j.dump(4, ' ', true); - std::string &delimiter = std::string("\n"); - std::string::size_type pos = 0, prev = 0; - while ((pos = jsondump.find(delimiter, prev)) != std::string::npos) { - s.Format(_T("%s %s\n"), CT[CT_JSON], ExportString(jsondump.substr(prev, pos - prev).c_str())); + if (!j.is_null()) { + std::string& jsondump = j.dump(4, ' ', true); + std::string& delimiter = std::string("\n"); + std::string::size_type pos = 0, prev = 0; + while ((pos = jsondump.find(delimiter, prev)) != std::string::npos) { + s.Format(_T("%s %s\n"), CT[CT_JSON], ExportString(jsondump.substr(prev, pos - prev).c_str())); + f.WriteString(s); + prev = pos + delimiter.size(); + } + s.Format(_T("%s %s\n"), CT[CT_JSON], ExportString(jsondump.substr(prev).c_str())); f.WriteString(s); - prev = pos + delimiter.size(); } - s.Format(_T("%s %s\n"), CT[CT_JSON], ExportString(jsondump.substr(prev).c_str())); - f.WriteString(s); } f.WriteString(_T("\n"));