From 4d2623bc2ae5c502aa9768da149886dda4eeeb7c Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 15 Mar 2012 00:25:54 +0000 Subject: [PATCH] Really fix crash when switching lines with the drag visual tool active Originally committed to SVN as r6588. --- aegisub/automation/autoload/clean-info.lua | 10 ++++++---- aegisub/src/visual_tool_drag.cpp | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/aegisub/automation/autoload/clean-info.lua b/aegisub/automation/autoload/clean-info.lua index 6265f9384..2f9f88862 100644 --- a/aegisub/automation/autoload/clean-info.lua +++ b/aegisub/automation/autoload/clean-info.lua @@ -32,16 +32,18 @@ function clean_script_info(subs) ["wrapstyle"] = true } + local deleted = 0 for i = 1, #subs do - if subs[i].class == "info" and not keep_keys[strlower(subs[i].key)] then - subs[i] = nil - i = i - 1 + local idx = i - deleted + if subs[idx].class == "info" and not keep_keys[subs[idx].key:lower()] then + subs.delete(idx) + deleted = deleted + 1 end end end function clean_script_info_macro(subs) - clean_script_info(sub) + clean_script_info(subs) aegisub.set_undo_point(script_name) end diff --git a/aegisub/src/visual_tool_drag.cpp b/aegisub/src/visual_tool_drag.cpp index 676f568b2..3d3f847fa 100644 --- a/aegisub/src/visual_tool_drag.cpp +++ b/aegisub/src/visual_tool_drag.cpp @@ -25,6 +25,9 @@ #include "visual_tool_drag.h" #ifndef AGI_PRE +#include +#include + #include #include #endif @@ -153,21 +156,27 @@ void VisualToolDrag::OnFrameChanged() { } } +template static bool cmp_line(T const& lft, T const& rgt) { + return lft->line == rgt->line; +} + +template static bool line_not_present(C const& set, T const& it) { + return find_if(set.begin(), set.end(), bind(cmp_line, it, std::tr1::placeholders::_1)) == set.end(); +} + void VisualToolDrag::OnSelectedSetChanged(const Selection &added, const Selection &removed) { c->selectionController->GetSelectedSet(selection); bool any_changed = false; - for (feature_iterator it = features.begin(); it != features.end(); ) { + for (feature_iterator it = features.begin(); it != features.end(); ++it) { if (removed.count(it->line)) { - sel_features.erase(it++); + sel_features.erase(it); any_changed = true; } - else if (added.count(it->line) && it->type == DRAG_START && !sel_features.count(it->parent)) { - sel_features.insert(it++); + else if (added.count(it->line) && it->type == DRAG_START && line_not_present(sel_features, it)) { + sel_features.insert(it); any_changed = true; } - else - ++it; } if (any_changed)