Really fix crash when switching lines with the drag visual tool active

Originally committed to SVN as r6588.
This commit is contained in:
Thomas Goyne 2012-03-15 00:25:54 +00:00
parent cbf9ee463e
commit 4d2623bc2a
2 changed files with 21 additions and 10 deletions

View File

@ -32,16 +32,18 @@ function clean_script_info(subs)
["wrapstyle"] = true ["wrapstyle"] = true
} }
local deleted = 0
for i = 1, #subs do for i = 1, #subs do
if subs[i].class == "info" and not keep_keys[strlower(subs[i].key)] then local idx = i - deleted
subs[i] = nil if subs[idx].class == "info" and not keep_keys[subs[idx].key:lower()] then
i = i - 1 subs.delete(idx)
deleted = deleted + 1
end end
end end
end end
function clean_script_info_macro(subs) function clean_script_info_macro(subs)
clean_script_info(sub) clean_script_info(subs)
aegisub.set_undo_point(script_name) aegisub.set_undo_point(script_name)
end end

View File

@ -25,6 +25,9 @@
#include "visual_tool_drag.h" #include "visual_tool_drag.h"
#ifndef AGI_PRE #ifndef AGI_PRE
#include <algorithm>
#include <tr1/functional>
#include <wx/bmpbuttn.h> #include <wx/bmpbuttn.h>
#include <wx/toolbar.h> #include <wx/toolbar.h>
#endif #endif
@ -153,21 +156,27 @@ void VisualToolDrag::OnFrameChanged() {
} }
} }
template<class T> static bool cmp_line(T const& lft, T const& rgt) {
return lft->line == rgt->line;
}
template<class C, class T> static bool line_not_present(C const& set, T const& it) {
return find_if(set.begin(), set.end(), bind(cmp_line<T>, it, std::tr1::placeholders::_1)) == set.end();
}
void VisualToolDrag::OnSelectedSetChanged(const Selection &added, const Selection &removed) { void VisualToolDrag::OnSelectedSetChanged(const Selection &added, const Selection &removed) {
c->selectionController->GetSelectedSet(selection); c->selectionController->GetSelectedSet(selection);
bool any_changed = false; 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)) { if (removed.count(it->line)) {
sel_features.erase(it++); sel_features.erase(it);
any_changed = true; any_changed = true;
} }
else if (added.count(it->line) && it->type == DRAG_START && !sel_features.count(it->parent)) { else if (added.count(it->line) && it->type == DRAG_START && line_not_present(sel_features, it)) {
sel_features.insert(it++); sel_features.insert(it);
any_changed = true; any_changed = true;
} }
else
++it;
} }
if (any_changed) if (any_changed)