Browse Source

Fixed a couple of crashes. most notably a crash in diagnostics when writing an extra } in the middle of code.

merge-requests/365/head
eidheim 10 years ago
parent
commit
a794bd5eec
  1. 12
      src/directories.cc
  2. 4
      src/directories.h
  3. 26
      src/source.cc

12
src/directories.cc

@ -12,7 +12,7 @@ namespace sigc {
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
} }
Directories::Directories() { Directories::Directories() : stop_update_thread(false) {
DEBUG("adding treeview to scrolledwindow"); DEBUG("adding treeview to scrolledwindow");
add(tree_view); add(tree_view);
set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
@ -69,8 +69,8 @@ Directories::Directories() {
update_mutex.unlock(); update_mutex.unlock();
}); });
std::thread update_thread([this](){ update_thread=std::thread([this](){
while(true) { while(!stop_update_thread) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
update_mutex.lock(); update_mutex.lock();
if(update_paths.size()==0) { if(update_paths.size()==0) {
@ -95,7 +95,11 @@ Directories::Directories() {
update_mutex.unlock(); update_mutex.unlock();
} }
}); });
update_thread.detach(); }
Directories::~Directories() {
stop_update_thread=true;
update_thread.join();
} }
void Directories::open(const boost::filesystem::path& dir_path) { void Directories::open(const boost::filesystem::path& dir_path) {

4
src/directories.h

@ -8,6 +8,7 @@
#include "cmake.h" #include "cmake.h"
#include <thread> #include <thread>
#include <mutex> #include <mutex>
#include <atomic>
class Directories : public Gtk::ScrolledWindow { class Directories : public Gtk::ScrolledWindow {
public: public:
@ -30,6 +31,7 @@ public:
}; };
Directories(); Directories();
~Directories();
void open(const boost::filesystem::path& dir_path=""); void open(const boost::filesystem::path& dir_path="");
void update(); void update();
void select(const boost::filesystem::path &path); void select(const boost::filesystem::path &path);
@ -46,6 +48,8 @@ private:
ColumnRecord column_record; ColumnRecord column_record;
std::unordered_map<std::string, std::pair<Gtk::TreeModel::Row, std::time_t> > last_write_times; std::unordered_map<std::string, std::pair<Gtk::TreeModel::Row, std::time_t> > last_write_times;
std::mutex update_mutex; std::mutex update_mutex;
std::thread update_thread;
std::atomic<bool> stop_update_thread;
Glib::Dispatcher update_dispatcher; Glib::Dispatcher update_dispatcher;
std::vector<std::string> update_paths; std::vector<std::string> update_paths;
}; };

26
src/source.cc

@ -658,8 +658,24 @@ void Source::ClangViewParse::update_diagnostics() {
auto diagnostics=clang_tu->get_diagnostics(); auto diagnostics=clang_tu->get_diagnostics();
for(auto &diagnostic: diagnostics) { for(auto &diagnostic: diagnostics) {
if(diagnostic.path==file_path.string()) { if(diagnostic.path==file_path.string()) {
auto start=get_buffer()->get_iter_at_line_index(diagnostic.offsets.first.line-1, diagnostic.offsets.first.index-1); auto start_line=get_line(diagnostic.offsets.first.line-1); //index is sometimes off the line
auto end=get_buffer()->get_iter_at_line_index(diagnostic.offsets.second.line-1, diagnostic.offsets.second.index-1); auto start_line_index=diagnostic.offsets.first.index-1;
if(start_line_index>=start_line.size()) {
if(start_line.size()==0)
start_line_index=0;
else
start_line_index=start_line.size()-1;
}
auto end_line=get_line(diagnostic.offsets.second.line-1); //index is sometimes off the line
auto end_line_index=diagnostic.offsets.second.index-1;
if(end_line_index>=end_line.size()) {
if(end_line.size()==0)
end_line_index=0;
else
end_line_index=end_line.size()-1;
}
auto start=get_buffer()->get_iter_at_line_index(diagnostic.offsets.first.line-1, start_line_index);
auto end=get_buffer()->get_iter_at_line_index(diagnostic.offsets.second.line-1, end_line_index);
std::string diagnostic_tag_name; std::string diagnostic_tag_name;
if(diagnostic.severity<=CXDiagnostic_Warning) if(diagnostic.severity<=CXDiagnostic_Warning)
diagnostic_tag_name="def:warning"; diagnostic_tag_name="def:warning";
@ -846,8 +862,9 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
if(line.size()>=config->tab_size) { if(line.size()>=config->tab_size) {
for(auto c: line) { for(auto c: line) {
if(c!=config->tab_char) { if(c!=config->tab_char) {
get_source_buffer()->insert_at_cursor("}");
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return Source::View::on_key_press_event(key); return true;
} }
} }
Gtk::TextIter insert_it = get_source_buffer()->get_insert()->get_iter(); Gtk::TextIter insert_it = get_source_buffer()->get_insert()->get_iter();
@ -858,8 +875,9 @@ bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
get_source_buffer()->erase(line_it, line_plus_it); get_source_buffer()->erase(line_it, line_plus_it);
} }
get_source_buffer()->insert_at_cursor("}");
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();
return Source::View::on_key_press_event(key); return true;
} }
get_source_buffer()->end_user_action(); get_source_buffer()->end_user_action();

Loading…
Cancel
Save