On 04/28/2013 12:29 PM, Vincent van Ravesteijn wrote:
Op 28-4-2013 18:13, Richard Heck schreef:
On 04/28/2013 10:25 AM, Vincent van Ravesteijn wrote:
Commit db358a (Richard Heck; Fix bug found by Scott concerning
copying XHTML to clipboard) introduces a bug that crashes LyX when
something is cut the second time.
Since commit 928dc0332 (Georg Baum; Fic crash for repeated pasting
from complex docs) LyX crashes immediately on every cut.
I can't seem to get this to happen on Linux.
It looks as if maybe the XHTML copying stuff is more complicated than
it seemed it would be. Perhaps it should be reverted for the moment,
until we figure out what is happening.
Do you have a backtrace?
Richard
No, I can't seem to get a useful backtrace.
What I did found out is that:
1) It seems strange that Georg renamed buffer to staticbuffer, but
then removed the static keyword.
Yes, surely unintended.
2) Using MarkAsExporting is not appropriate if we delete the buffer
anyway. And more importantly, buffer is deleted *before*
MarkAsExporting. The latter causes the crash as it accesses the
deleted buffer.
A simple fix would therefore be to scope that variable.
As things are, we actually do need to mark it as exporting, because
otherwise we do not collect the right information during updateMacros.
Some of the logic here could be changed, but there are other places we
want to know if we are doing an export, and the best place to keep that
flag seems to be in the Buffer itself.
We actually need a different "mark" here. We should NOT be converting
all the images to pngs or whatever just because we are copying HTML to
the clipboard. I've been meaning to have a look at this myself.
I've attached a patch that is at least proof of concept.
Richard
>From db262751629dc028c2328c4261f4adad606f34e3 Mon Sep 17 00:00:00 2001
From: Richard Heck <rgh...@lyx.org>
Date: Sun, 28 Apr 2013 12:58:21 -0400
Subject: [PATCH] Simple fix.
---
src/CutAndPaste.cpp | 46 +++++++++++++++++++++++++---------------------
1 file changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index b996d8a..6c491ac 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -478,7 +478,7 @@ void putClipboard(ParagraphList const & paragraphs,
// to be so, but the alternative is to construct a new one of these (with a
// new temporary directory, etc) every time, and then to destroy it. So maybe
// it's worth just keeping this one around.
- Buffer * staticbuffer = theBufferList().newInternalBuffer(
+ static Buffer * staticbuffer = theBufferList().newInternalBuffer(
FileName::tempName("clipboard.internal").absFileName());
// These two things only really need doing the first time.
@@ -504,26 +504,30 @@ void putClipboard(ParagraphList const & paragraphs,
// applications, the number that can parse it should go up in the future.
buffer->params().html_math_output = BufferParams::MathML;
- // The Buffer is being used to export. This is necessary so that the
- // updateMacros call will record the needed information.
- MarkAsExporting mex(buffer);
-
- buffer->updateBuffer(Buffer::UpdateMaster, OutputUpdate);
- buffer->updateMacros();
- buffer->updateMacroInstances(OutputUpdate);
-
- // LyX's own format
- string lyx;
- ostringstream oslyx;
- if (buffer->write(oslyx))
- lyx = oslyx.str();
-
- // XHTML format
- odocstringstream oshtml;
- OutputParams runparams(encodings.fromLyXName("utf8"));
- buffer->writeLyXHTMLSource(oshtml, runparams, Buffer::FullSource);
-
- theClipboard().put(lyx, oshtml.str(), plaintext);
+ {
+ // The Buffer is being used to export. This is necessary so that the
+ // updateMacros call will record the needed information.
+ // We scope this variable because we otherwise get a crash when we
+ // delete the Buffer before this goes out of scope.
+ MarkAsExporting mex(buffer);
+
+ buffer->updateBuffer(Buffer::UpdateMaster, OutputUpdate);
+ buffer->updateMacros();
+ buffer->updateMacroInstances(OutputUpdate);
+
+ // LyX's own format
+ string lyx;
+ ostringstream oslyx;
+ if (buffer->write(oslyx))
+ lyx = oslyx.str();
+
+ // XHTML format
+ odocstringstream oshtml;
+ OutputParams runparams(encodings.fromLyXName("utf8"));
+ buffer->writeLyXHTMLSource(oshtml, runparams, Buffer::FullSource);
+
+ theClipboard().put(lyx, oshtml.str(), plaintext);
+ }
// Save that memory
delete buffer;
--
1.7.11.7