Joost Verburg wrote:
Abdelrazak Younes wrote:
Hum... the call to dialog().CancelButton() seems superfluous in
ControlSpellchecker::checkAlive(). That may well be the cause of your
crash. Could you please try out this patch? If it works then it can
easily be backported to 1.4.
But I still don't understand why I don't see a crash...
This fixes the crash. However I now get an endless loop of "The
spellchecker controller has been killed" message boxes.
OK, let's use a hammer then.
This patch avoid the deletion of the Aspell object. If it works, it
could be adapted for 1.4 without any feature removal (that is pspell and
ispell). Then, the spellchecker code in trunk could use a lifting...
Abdel.
Index: aspell.C
===================================================================
--- aspell.C (revision 14911)
+++ aspell.C (working copy)
@@ -23,9 +23,18 @@
using std::string;
-ASpell::ASpell(BufferParams const &, string const & lang)
+ASpell::ASpell(string const & lang)
: els(0), spell_error_object(0)
{
+ if (!lang.empty())
+ addSpeller(lang);
+}
+
+
+void ASpell::reset(string const & lang)
+{
+ els = 0;
+ spell_error_object =0;
addSpeller(lang);
}
Index: aspell_local.h
===================================================================
--- aspell_local.h (revision 14911)
+++ aspell_local.h (working copy)
@@ -30,7 +30,7 @@
/**
* Initialise the spellchecker with the given buffer params and
language.
*/
- ASpell(BufferParams const & params, std::string const & lang);
+ ASpell(std::string const & lang = "");
virtual ~ASpell();
@@ -55,6 +55,9 @@
/// give an error message on messy exit
virtual std::string const error();
+ /// reset the spellchecker with the given language.
+ void reset(std::string const & lang);
+
private:
/// add a speller of the given language
void addSpeller(std::string const & lang);
Index: frontends/controllers/ControlSpellchecker.C
===================================================================
--- frontends/controllers/ControlSpellchecker.C (revision 14911)
+++ frontends/controllers/ControlSpellchecker.C (working copy)
@@ -56,7 +56,12 @@
ControlSpellchecker::ControlSpellchecker(Dialog & parent)
: Dialog::Controller(parent), exitEarly_(false),
oldval_(0), newvalue_(0), count_(0)
-{}
+{
+#if defined(USE_ASPELL)
+ if (lyxrc.use_spell_lib)
+ speller_.reset(new ASpell);
+#endif
+}
ControlSpellchecker::~ControlSpellchecker()
@@ -71,11 +76,8 @@
? lyxrc.isp_alt_lang
: bp.language->code();
-#if defined(USE_ASPELL)
+#if defined(USE_PSPELL)
if (lyxrc.use_spell_lib)
- return new ASpell(bp, lang);
-#elif defined(USE_PSPELL)
- if (lyxrc.use_spell_lib)
return new PSpell(bp, lang);
#endif
@@ -96,7 +98,15 @@
{
lyxerr[Debug::GUI] << "Spellchecker::initialiseParams" << endl;
+#if defined(USE_ASPELL)
+ string lang = (lyxrc.isp_use_alt_lang)
+ ? lyxrc.isp_alt_lang
+ : kernel().buffer().params().language->code();
+ static_cast<ASpell *>(speller_.get())->reset(lang);
+#else
speller_.reset(getSpeller(kernel().buffer().params()));
+#endif
+
if (!speller_.get())
return false;
@@ -111,7 +121,9 @@
Alert::error(_("Spellchecker error"),
_("The spellchecker could not be started\n")
+ speller_->error());
+#ifndef USE_ASPELL
speller_.reset(0);
+#endif
}
return success;
@@ -121,7 +133,9 @@
void ControlSpellchecker::clearParams()
{
lyxerr[Debug::GUI] << "Spellchecker::clearParams" << endl;
- speller_.reset(0);
+#ifndef USE_ASPELL
+ speller_.reset(0);
+#endif
}
@@ -260,9 +274,18 @@
bool ControlSpellchecker::checkAlive()
{
+ if (!speller_.get()) {
+ Alert::error(_("The spellchecker controller has been killed\n"),
+ _("Looks like a bug, please contact [EMAIL
PROTECTED]"));
+ dialog().CancelButton();
+ return false;
+ }
+
if (speller_->alive() && speller_->error().empty())
return true;
+ dialog().CancelButton();
+
string message;
if (speller_->error().empty())
message = _("The spellchecker has died for some reason.\n"
@@ -271,8 +294,6 @@
message = _("The spellchecker has failed.\n")
+ speller_->error();
- dialog().CancelButton();
-
Alert::error(_("The spellchecker has failed"), message);
return false;
}
@@ -280,7 +301,10 @@
void ControlSpellchecker::showSummary()
{
- if (!checkAlive() || count_ == 0) {
+ if (!checkAlive())
+ return;
+
+ if (count_ == 0) {
dialog().CancelButton();
return;
}