http://www.lyx.org/trac/ticket/6944

I had a go on that bug, which I consider the last mustfix before an 1.6.8 
release. The attached patch is against branch and fixes the crash for me.

However, I'm not sure I really understand the func queue idea, so I'd 
appreciate a careful and critical review.

The idea of the patch is to only fill the queue within the loop (while 
processing multiple files in a drop event), and then process the queue after 
the loop was iterated. Until now, the processQueue was filled and processed 
asynchronously (via a QTimer) immediately at every iteration. My impression is 
that the crash was triggered by some kind of race condition triggered by this 
procedure.

The second thing I did is fixing a thinko (I think). In 
GuiApplication::processFuncRequestQueue(), the queue was handled from the 
back(), but pop() removes elements at the front(). Therefore we need to 
process the queue from the front() side (which also makes sense logically, 
given that we want to handle the funcs according to the "first come, first 
serve" principle).

Does this make sense?

Jürgen
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp	(Revision 35694)
+++ src/frontends/qt4/GuiView.cpp	(Arbeitskopie)
@@ -697,9 +697,10 @@
 		// Asynchronously post the event. DropEvent usually come
 		// from the BufferView. But reloading a file might close
 		// the BufferView from within its own event handler.
-		guiApp->dispatchDelayed(cmd);
+		guiApp->addtoFuncRequestQueue(cmd);
 		event->accept();
 	}
+	guiApp->performFuncRequests();
 }
 
 
Index: src/frontends/qt4/GuiApplication.cpp
===================================================================
--- src/frontends/qt4/GuiApplication.cpp	(Revision 35694)
+++ src/frontends/qt4/GuiApplication.cpp	(Arbeitskopie)
@@ -947,6 +947,18 @@
 }
 
 
+void GuiApplication::addtoFuncRequestQueue(FuncRequest const & func)
+{
+	d->func_request_queue_.push(func);
+}
+
+
+void GuiApplication::performFuncRequests()
+{
+	processFuncRequestQueue();
+}
+
+
 void GuiApplication::resetGui()
 {
 	// Set the language defined by the user.
@@ -1130,7 +1142,7 @@
 void GuiApplication::processFuncRequestQueue()
 {
 	while (!d->func_request_queue_.empty()) {
-		lyx::dispatch(d->func_request_queue_.back());
+		lyx::dispatch(d->func_request_queue_.front());
 		d->func_request_queue_.pop();
 	}
 }
Index: src/frontends/qt4/GuiApplication.h
===================================================================
--- src/frontends/qt4/GuiApplication.h	(Revision 35694)
+++ src/frontends/qt4/GuiApplication.h	(Arbeitskopie)
@@ -60,6 +60,8 @@
 	bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
 	bool dispatch(FuncRequest const &);
 	void dispatchDelayed(FuncRequest const &);
+	void addtoFuncRequestQueue(FuncRequest const &);
+	void performFuncRequests();
 	void resetGui();
 	void restoreGuiSession();
 	Clipboard & clipboard();

Reply via email to