Fixed at r33674, I think. Here's the problem.

When we clone the buffer, we create a child. But now when we validate the buffer, we go through InsetInclude::loadIfNeeded():

Buffer * InsetInclude::loadIfNeeded() const
{
// This is for background export and preview. We don't want to load the
    // cloned child document again.
    if (child_buffer_ && theBufferList().isLoaded(child_buffer_)
&& child_buffer_->isClone())
        return child_buffer_;

This check was always false, because theBufferList() doesn't know about cloned buffers.

    // Don't try to load it again if we failed before.
    if (failedtoload_ || isVerbatim(params()) || isListings(params()))
        return 0;

    FileName const included_file = includedFilename(buffer(), params());
    // Use cached Buffer if possible.
    if (child_buffer_ != 0) {
        if (theBufferList().isLoaded(child_buffer_)

So this is false, too.

            // additional sanity check: make sure the Buffer really is
            // associated with the file we want.
&& child_buffer_ == theBufferList().getBuffer(included_file))
            return child_buffer_;
        // Buffer vanished, so invalidate cache and try to reload.
        child_buffer_ = 0;
    }

And now we have invalidated the child_buffer_.

    if (!isLyXFilename(included_file.absFilename()))
        return 0;

    Buffer * child = theBufferList().getBuffer(included_file);

But the filename associated with that child buffer is that of the old included file! So this will return the ORIGINAL loaded child.

    if (!child) {
        [snip]
    }
    child->setParent(&buffer());

And now the original loaded child gets its parent set to the CLONE. So when the clone gets deleted, so does the ORIGINAL child.

rh

Reply via email to