diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-06-27 22:16:04 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-06-27 22:50:30 +0200 |
| commit | 4b2a91af4331c1c7bc540fb352b1099292b5f753 (patch) | |
| tree | 799a169f29bf7b4c934dc8f52840adbbea1c824e | |
| parent | 9b9088756ad46190ae25aac568fb05b36c2237eb (diff) | |
Speculative fix for assertion failure (DoM #2839).v1.8.101
| -rw-r--r-- | src/verify.cc | 25 | ||||
| -rw-r--r-- | test/verify_test.cc | 34 |
2 files changed, 51 insertions, 8 deletions
diff --git a/src/verify.cc b/src/verify.cc index 9389d438..ec8925f2 100644 --- a/src/verify.cc +++ b/src/verify.cc @@ -81,6 +81,7 @@ #include <boost/algorithm/string.hpp> #include <iostream> #include <map> +#include <numeric> #include <regex> #include <set> #include <vector> @@ -1239,16 +1240,21 @@ dcp::verify_text_lines_and_characters( return a->time < b->time; }); - map<int, int> current; + /* The number of characters currently displayed at different vertical positions, i.e. on + * what we consider different lines. Key is the vertical position (0 to 100) and the value + * is a list of the active subtitles in that position. + */ + map<int, vector<shared_ptr<Event>>> current; for (auto i: events) { if (current.size() > 3) { result->line_count_exceeded = true; } for (auto j: current) { - if (j.second > warning_length) { + int length = std::accumulate(j.second.begin(), j.second.end(), 0, [](int total, shared_ptr<const Event> event) { return total + event->characters; }); + if (length > warning_length) { result->warning_length_exceeded = true; } - if (j.second > error_length) { + if (length > error_length) { result->error_length_exceeded = true; } } @@ -1256,17 +1262,20 @@ dcp::verify_text_lines_and_characters( if (i->start) { /* end of a subtitle */ DCP_ASSERT (current.find(i->start->position) != current.end()); - if (current[i->start->position] == i->start->characters) { + auto current_position = current[i->start->position]; + auto iter = std::find(current_position.begin(), current_position.end(), i->start); + if (iter != current_position.end()) { + current_position.erase(iter); + } + if (current_position.empty()) { current.erase(i->start->position); - } else { - current[i->start->position] -= i->start->characters; } } else { /* start of a subtitle */ if (current.find(i->position) == current.end()) { - current[i->position] = i->characters; + current[i->position] = vector<shared_ptr<Event>>{i}; } else { - current[i->position] += i->characters; + current[i->position].push_back(i); } } } diff --git a/test/verify_test.cc b/test/verify_test.cc index 5a9489fe..eab50b59 100644 --- a/test/verify_test.cc +++ b/test/verify_test.cc @@ -3986,3 +3986,37 @@ BOOST_AUTO_TEST_CASE(verify_encrypted_smpte_dcp) } +BOOST_AUTO_TEST_CASE(overlapping_subtitles) +{ + auto asset = make_shared<dcp::InteropSubtitleAsset>(); + + asset->add(std::make_shared<dcp::SubtitleString>( + optional<string>{}, false, false, false, + dcp::Colour{}, 42, 0, + dcp::Time(0, 0, 0, 0, 24), + dcp::Time(0, 0, 8, 0, 24), + 0, dcp::HAlign::CENTER, + 0, dcp::VAlign::CENTER, + 0, + dcp::Direction::LTR, + "", + dcp::Effect::NONE, dcp::Colour{}, dcp::Time{}, dcp::Time{}, 0, vector<dcp::Ruby>{} + )); + + asset->add(std::make_shared<dcp::SubtitleString>( + optional<string>{}, false, false, false, + dcp::Colour{}, 42, 0, + dcp::Time(0, 0, 2, 0, 24), + dcp::Time(0, 0, 4, 0, 24), + 0, dcp::HAlign::CENTER, + 0, dcp::VAlign::CENTER, + 0, + dcp::Direction::LTR, + "Hello", + dcp::Effect::NONE, dcp::Colour{}, dcp::Time{}, dcp::Time{}, 0, vector<dcp::Ruby>{} + )); + + dcp::LinesCharactersResult result; + dcp::verify_text_lines_and_characters(asset, 64, 80, &result); +} + |
