As I have analyzed in another email, the crash is caused by 1. load child doc 2 ==> child doc 2 loaded, switch to child doc 2, setBuffer(child doc 2), which disconnect the master buffer.
2. load child doc 1 ==> child doc 1 loaded, fire structureChanged() from its master buffer. However, the master buffer is currently disconnected so updateToc is not called. 3. When the Toc panel is updated, its Toc is outdated, leading to MSVC iterator validation assertion. Attached patch fixes the crash, although I am not quite sure about other side effects. My understanding is that this remaining signal will not cause any harm even if it becomes broken later. Cheers, Bo
Index: src/frontends/LyXView.cpp =================================================================== --- src/frontends/LyXView.cpp (revision 19272) +++ src/frontends/LyXView.cpp (working copy) @@ -308,7 +308,21 @@ { errorsConnection_.disconnect(); bufferChangedConnection_.disconnect(); - bufferStructureChangedConnection_.disconnect(); + // http://bugzilla.lyx.org/show_bug.cgi?id=4096 + // + // The master buffer, even when it is not the current buffer and is + // disconnected by setBuffer(its_child_buffer), need to accept + // structureChanged() signal so that updateToc() can be called properly + // to update Toc for this document. Otherwise, bug 4096 will crash lyx, + // which is caused by + // load child doc 2 ==> child doc 2 loaded + // connect child doc2 + // disconnect master doc + // load child doc 1 ==> child doc 1 loaded + // fire structureChanged() + // updateToc() is not called because master buffer is disconnected + // + // bufferStructureChangedConnection_.disconnect(); messageConnection_.disconnect(); busyConnection_.disconnect(); titleConnection_.disconnect();