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
}
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

View file

@ -25,6 +25,9 @@
#include "visual_tool_drag.h"
#ifndef AGI_PRE
#include <algorithm>
#include <tr1/functional>
#include <wx/bmpbuttn.h>
#include <wx/toolbar.h>
#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) {
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)