Re: Undocked Outliner & multiple window crashes [#11004] (was: Beamer & Outliner broken)

2018-03-12 Thread Pavel Sanda
Pavel Sanda wrote:
> Scott Kostyshak wrote:
> > On Fri, Jan 12, 2018 at 05:20:18PM +, Pavel Sanda wrote:
> > > Pavel Sanda wrote:
> > > > after pushing the outliner button we call in TocWidget::outline generic
> > > > GuiApplication::dispatch which likely grabs currently active window; if 
> > > > that's
> > > > the wrong window, it grabs wrong cursor position, moves wrong section 
> > > > and
> > > > suddenly content of outliner and buffer structure are out of sync and 
> > > > crash is
> > > > just matter of time
> > > > 
> > > > Now this is not some glitch but rather conceptual problem how we handle 
> > > > lfuns from the widget(s).
> > > > Opinions how to move forward?
> > > 
> > > E.g. I could implement requested_guiview inside FuncRequest so we could 
> > > specify window
> > > as the lfun request travels through GuiApplication. Any objections to 
> > > this solution?
> > 
> > Bump.
> > 
> > Scott
> 
> I have patch along the lines above, i.e. when we request lyx::dispatch we also
> provide guiview inside FuncRequest, so we can at least detect in
> guiapplication::dispatch that current_view is different and stop there. So 
> this
> crash is gone.
> 
> Various attempts with raise/activewindow/setcurrentview for getting the right
> window up in the first place did not seem to work. But it is difficult to be
> sure, the scenario of multiple windows+undocked outliner is minefield with
> crashes stemming from different reasons.

I commited the fix for the crash above in 8725614e3f. The other one would need 
longer debug session.

Pavel

> There is immediately different crash - apparently when we load already
> opened buffer in new window, the load resets tocwidget from the oldwindow
> and if you click to some toc item without focusing old window first you often
> get crash, see below.
> 
> Thread 1 "lyx" received signal SIGSEGV, Segmentation fault.
> 0x557742fd in lyx::CursorSlice::text (this=, 
> this=) at CursorSlice.h:119
> 119 Text * text() const { return inset_->getText(idx_); }
> (gdb) bt
> #0  0x557742fd in lyx::CursorSlice::text (this=, 
> this=) at CursorSlice.h:119
> #1  lyx::DocIterator::innerTextSlice (this=0x7fffcbd0) at 
> DocIterator.cpp:233
> #2  0x55774419 in 
> lyx::DocIterator::paragraphGotoArgument[abi:cxx11]() const (this= out>) at DocIterator.cpp:247
> #3  0x558ae1eb in lyx::TocItem::action 
> (this=this@entry=0x7fffcbd0) at TocBackend.cpp:75
> #4  0x55bbcc5f in lyx::frontend::TocModels::goTo (this= out>, type=..., index=...) at TocModel.cpp:316
> #5  0x55d1ebc6 in lyx::frontend::TocWidget::goTo 
> (this=this@entry=0x56b42330, index=...) at TocWidget.cpp:252
> #6  0x55d1ec0b in lyx::frontend::TocWidget::on_tocTV_pressed 
> (this=0x56b42330, index=...) at TocWidget.cpp:240
> ...
> 
> I saw that when loading the buffer in new window the new guiview points to
> buffer, which has pointer to old guiview. That trigers toc updates in old
> window. Is this expected??? I seem to be somewhat lost why buffer has
> pointer to guiview at all when multiple windows are possible.
> 
> Pavel


Undocked Outliner & multiple window crashes [#11004] (was: Beamer & Outliner broken)

2018-02-02 Thread Pavel Sanda
Scott Kostyshak wrote:
> On Fri, Jan 12, 2018 at 05:20:18PM +, Pavel Sanda wrote:
> > Pavel Sanda wrote:
> > > after pushing the outliner button we call in TocWidget::outline generic
> > > GuiApplication::dispatch which likely grabs currently active window; if 
> > > that's
> > > the wrong window, it grabs wrong cursor position, moves wrong section and
> > > suddenly content of outliner and buffer structure are out of sync and 
> > > crash is
> > > just matter of time
> > > 
> > > Now this is not some glitch but rather conceptual problem how we handle 
> > > lfuns from the widget(s).
> > > Opinions how to move forward?
> > 
> > E.g. I could implement requested_guiview inside FuncRequest so we could 
> > specify window
> > as the lfun request travels through GuiApplication. Any objections to this 
> > solution?
> 
> Bump.
> 
> Scott

I have patch along the lines above, i.e. when we request lyx::dispatch we also
provide guiview inside FuncRequest, so we can at least detect in
guiapplication::dispatch that current_view is different and stop there. So this
crash is gone.

Various attempts with raise/activewindow/setcurrentview for getting the right
window up in the first place did not seem to work. But it is difficult to be
sure, the scenario of multiple windows+undocked outliner is minefield with
crashes stemming from different reasons.


There is immediately different crash - apparently when we load already
opened buffer in new window, the load resets tocwidget from the oldwindow
and if you click to some toc item without focusing old window first you often
get crash, see below.

Thread 1 "lyx" received signal SIGSEGV, Segmentation fault.
0x557742fd in lyx::CursorSlice::text (this=, 
this=) at CursorSlice.h:119
119 Text * text() const { return inset_->getText(idx_); }
(gdb) bt
#0  0x557742fd in lyx::CursorSlice::text (this=, 
this=) at CursorSlice.h:119
#1  lyx::DocIterator::innerTextSlice (this=0x7fffcbd0) at 
DocIterator.cpp:233
#2  0x55774419 in lyx::DocIterator::paragraphGotoArgument[abi:cxx11]() 
const (this=) at DocIterator.cpp:247
#3  0x558ae1eb in lyx::TocItem::action (this=this@entry=0x7fffcbd0) 
at TocBackend.cpp:75
#4  0x55bbcc5f in lyx::frontend::TocModels::goTo (this=, 
type=..., index=...) at TocModel.cpp:316
#5  0x55d1ebc6 in lyx::frontend::TocWidget::goTo 
(this=this@entry=0x56b42330, index=...) at TocWidget.cpp:252
#6  0x55d1ec0b in lyx::frontend::TocWidget::on_tocTV_pressed 
(this=0x56b42330, index=...) at TocWidget.cpp:240
...

I saw that when loading the buffer in new window the new guiview points to
buffer, which has pointer to old guiview. That trigers toc updates in old
window. Is this expected??? I seem to be somewhat lost why buffer has
pointer to guiview at all when multiple windows are possible.

Pavel
diff --git a/src/FuncRequest.cpp b/src/FuncRequest.cpp
index cd47c55595..ef357ee447 100644
--- a/src/FuncRequest.cpp
+++ b/src/FuncRequest.cpp
@@ -31,38 +31,39 @@ FuncRequest const FuncRequest::noaction(LFUN_NOACTION);
 
 FuncRequest::FuncRequest(Origin o)
: action_(LFUN_NOACTION), origin_(o), x_(0), y_(0),
- button_(mouse_button::none), modifier_(NoModifier)
+ button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
 {}
 
 
 FuncRequest::FuncRequest(FuncCode act, Origin o)
: action_(act), origin_(o), x_(0), y_(0),
-   button_(mouse_button::none), modifier_(NoModifier)
+   button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
 {}
 
 
 FuncRequest::FuncRequest(FuncCode act, docstring const & arg, Origin o)
: action_(act), argument_(arg), origin_(o), x_(0), y_(0),
- button_(mouse_button::none), modifier_(NoModifier)
+ button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
 {}
 
 
 FuncRequest::FuncRequest(FuncCode act, string const & arg, Origin o)
: action_(act), argument_(from_utf8(arg)), origin_(o), x_(0), y_(0),
- button_(mouse_button::none), modifier_(NoModifier)
+ button_(mouse_button::none), modifier_(NoModifier), view_origin_(0)
 {}
 
 
 FuncRequest::FuncRequest(FuncCode act, int ax, int ay,
 mouse_button::state but, KeyModifier modifier, Origin 
o)
: action_(act), origin_(o), x_(ax), y_(ay), button_(but),
- modifier_(modifier)
+ modifier_(modifier), view_origin_(0)
 {}
 
 
 FuncRequest::FuncRequest(FuncRequest const & cmd, docstring const & arg, 
Origin o)
: action_(cmd.action()), argument_(arg), origin_(o),
- x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier)
+ x_(cmd.x_), y_(cmd.y_), button_(cmd.button_), modifier_(NoModifier),
+ view_origin_(0)
 {}
 
 
diff --git a/src/FuncRequest.h b/src/FuncRequest.h
index 20cd96ab66..80587f9f01 100644
--- a/src/FuncRequest.h
+++ b/src/FuncRequest.h
@@ -24,6 +24,10 @@ namespace lyx {
 
 class LyXErr;
 
+namespace frontend {
+