Here's a slightly improved patch, that does a little cleanup along the way.
Richard
Richard Heck wrote:
Bo Peng wrote:
On 8/2/07, Richard Heck <[EMAIL PROTECTED]> wrote:
This fixes the crash, but I think it hides the real problem. I'm
sending
a patch in a moment that I think deals with the underlying issue.
So my understanding of the 'real problem' is different from yours. :-)
I think the real problem is that the master document is disconnected
when it is not the current buffer, so updateToc can not be properly
called when another child document is called, or when a child document
changes its structure. The latter is a more serious problem.
As long as something's connected, the master buffer will get this
signal, it turns out:
bufferStructureChangedConnection_ =
buf.getMasterBuffer()->structureChanged.connect(
boost::bind(&LyXView::updateToc, this));
So structureChanged() is always connected to the master buffer of
whatever buffer is connected.
It may be the case right now that the structure is forcefully changed
when a
child document is changed, but it is nevertheless logical to always
connect a buffer with this structureChanged() signal.
The patch I sent essentially makes it the case that some buffer is
always connected, if there's one open. At least that's the idea. So
the solutions are pretty much the same, in their effect: They keep the
master buffer connected. Mine makes more sense, though, at least to
me ;-), in large part because it has the extra safety feature of
keeping a buffer connected. There could be other problems caused by
disconnecting and then waiting around for ages until we connect again.
I'm inclined to make disconnectBuffer() private, and make
connectBuffer() call it when it is called with a null pointer. Then
you REALLY can't have no buffer connected.
Richard
--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto
Index: src/BufferView.h
===================================================================
--- src/BufferView.h (revision 19264)
+++ src/BufferView.h (working copy)
@@ -86,7 +86,8 @@
/// set the buffer we are viewing.
/// \todo FIXME: eventually, we will create a new BufferView
/// when switching Buffers, so this method should go.
- void setBuffer(Buffer * b);
+ /// returns the buffer currently set
+ Buffer * setBuffer(Buffer * b);
/// return the buffer being viewed.
Buffer * buffer() const;
Index: src/BufferView.cpp
===================================================================
--- src/BufferView.cpp (revision 19264)
+++ src/BufferView.cpp (working copy)
@@ -143,7 +143,7 @@
}
-void BufferView::setBuffer(Buffer * b)
+Buffer * BufferView::setBuffer(Buffer * b)
{
LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION
<< "[ b = " << b << "]" << endl;
@@ -182,7 +182,7 @@
// If we're quitting lyx, don't bother updating stuff
if (quitting) {
buffer_ = 0;
- return;
+ return 0;
}
//FIXME Fix for bug 3440 is here.
@@ -209,7 +209,7 @@
offset_ref_ = 0;
if (!buffer_)
- return;
+ return 0;
LYXERR(Debug::INFO) << BOOST_CURRENT_FUNCTION
<< "Buffer addr: " << buffer_ << endl;
@@ -243,6 +243,7 @@
if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
graphics::Previews::get().generateBufferPreviews(*buffer_);
+ return buffer_;
}
Index: src/frontends/LyXView.cpp
===================================================================
--- src/frontends/LyXView.cpp (revision 19264)
+++ src/frontends/LyXView.cpp (working copy)
@@ -133,18 +133,14 @@
// parentfilename will be used in case when we switch to a child
// document (hence when child_document is true)
string parentfilename;
- if (oldBuffer) {
+ if (oldBuffer)
parentfilename = oldBuffer->fileName();
- disconnectBuffer();
- }
if (!b && theBufferList().empty())
getDialogs().hideBufferDependent();
- work_area_->bufferView().setBuffer(b);
+ Buffer * newBuffer = work_area_->bufferView().setBuffer(b);
- //FIXME This would be a little simpler if setBuffer returned the buffer.
- Buffer * newBuffer = work_area_->bufferView().buffer();
if (newBuffer) {
if (child_document && newBuffer->getMasterBuffer() != oldBuffer) {
// Set the parent name of the child document.
@@ -160,7 +156,7 @@
// must update the labels and section numbering of its master
// Buffer.
updateLabels(*oldBuffer->getMasterBuffer());
-
+ //if (oldBuffer) disconnectBuffer(); done automatically
connectBuffer(*newBuffer);
/* FIXME: We need to rebuild the Toc dialog before the others even
@@ -178,7 +174,8 @@
// hidden. This should go here because some dialogs (eg ToC)
// require bv_->text.
getDialogs().updateBufferDependent(true);
- }
+ } else
+ disconnectBuffer();
if (quitting)
return;