Re: Lyx/branch crashes during exit.

2007-09-12 Thread Enrico Forestieri
On Wed, Sep 12, 2007 at 06:05:44PM +0200, Juergen Spitzmueller wrote:
> Enrico Forestieri wrote:
> 
> > So, Jürgen?
> 
> This is not an area where I feel very much at home, but I guess you are, so
> I just trust you. Put it in.

The fontconfig docs state that "There is a default configuration which
applications may use by passing 0 to any function using the data within
a FcConfig".

However, it turns out that support for FcConfigAppFontClear(0) was
only added in version 2.2.92:
http://www.fontconfig.org/release/ChangeLog-2.2.92
(search for FcConfigAppFontClear at the above URL)

I had a look at the Qt sources and ascertained that removeApplicationFont
calls FcConfigAppFontClear(0), hence the crash with fontconfig versions
less than 2.2.92.

I am going to put the patch in. In case it turns out that there is
a problem when not cleaning up by ourselves, we could revisit the
all matter. Indeed, the crash can be avoided by simply asking fontconfig
for a pointer to the default configuration (in this respect I also
regard this as a Qt bug).

Anyway, the current solution is the most clean, IMO, as it holds for
all platforms and avoids #ifdef's.

-- 
Enrico


Re: Lyx/branch crashes during exit.

2007-09-12 Thread Juergen Spitzmueller
Enrico Forestieri wrote:

> So, Jürgen?

This is not an area where I feel very much at home, but I guess you are, so
I just trust you. Put it in.

Jürgen



Re: Lyx/branch crashes during exit.

2007-09-12 Thread Enrico Forestieri
On Wed, Sep 12, 2007 at 09:24:09AM -0500, Bo Peng wrote:
> > The attached patch should solve the problem. As the added fonts are
> > application specific, fontconfig should do the cleanup for us, even
> > if the docs say nothing to this end.
> 
> I tested this patch against the branch and I can confirm that it fixes
> the crash. You should explain to Jurgen what this patch does and put
> it to branch (and trunk).

So, Jürgen?

This is clearly a bug in some old versions of fontconfig, as demonstrated
by the backtrace I am getting with fontconfig 2.2.3:

Program received signal SIGSEGV, Segmentation fault.
0xfe4c3250 in FcConfigAppFontClear () from /usr/lib/libfontconfig.so.1
(gdb) bt
#0  0xfe4c3250 in FcConfigAppFontClear () from /usr/lib/libfontconfig.so.1
#1  0xfeb11a08 in QFontDatabase::removeApplicationFont ()
   from /opt/qt4/lib/libQtGui.so.4
#2  0x00479e48 in lyx::frontend::GuiFontLoader::~GuiFontLoader ()
#3  0x0043eb44 in lyx::frontend::GuiApplication::~GuiApplication ()
#4  0x00181fe0 in lyx::LyX::prepareExit ()
#5  0x0018f840 in lyx::LyX::exec ()
#6  0x001415d4 in main ()

-- 
Enrico


Re: Lyx/branch crashes during exit.

2007-09-12 Thread Bo Peng
> The attached patch should solve the problem. As the added fonts are
> application specific, fontconfig should do the cleanup for us, even
> if the docs say nothing to this end.

I tested this patch against the branch and I can confirm that it fixes
the crash. You should explain to Jurgen what this patch does and put
it to branch (and trunk).

Cheers,
Bo


Re: Lyx/branch crashes during exit.

2007-09-12 Thread Enrico Forestieri
On Wed, Sep 12, 2007 at 01:00:02AM -0500, Bo Peng wrote:
> > I will compile with gcc 4 and try again.
> 
> Gcc4 + Qt 422 crashes.
> 
> Gcc4 + Qt 4.0 (or 4.11? not sure) does not.

Because that code is only compiled in for Qt >= 4.2

> Have not tested Gcc 3 + Qt 4.0, but it is likely a Qt 422 problem.

No, this must be a fontconfig problem. I tested it and saw that it
crashes with fontconfig version 2.2.3 but not with 2.4.2.

The attached patch should solve the problem. As the added fonts are
application specific, fontconfig should do the cleanup for us, even
if the docs say nothing to this end.

-- 
Enrico
Index: src/frontends/qt4/GuiFontLoader.cpp
===
--- src/frontends/qt4/GuiFontLoader.cpp (revision 20235)
+++ src/frontends/qt4/GuiFontLoader.cpp (working copy)
@@ -196,19 +196,17 @@
 GuiFontLoader::GuiFontLoader()
 {
 #if QT_VERSION >= 0x040200
-   fontID = new int[num_math_fonts];
-
string const fonts_dir =
addPath(package().system_support().absFilename(), "fonts");
 
for (int i = 0 ; i < num_math_fonts; ++i) {
string const font_file = lyx::support::os::external_path(
addName(fonts_dir, math_fonts[i] + ".ttf"));
-   fontID[i] = 
QFontDatabase::addApplicationFont(toqstr(font_file));
+   int fontID = 
QFontDatabase::addApplicationFont(toqstr(font_file));
 
LYXERR(Debug::FONT) << "Adding font " << font_file
<< static_cast
-   (fontID[i] < 0 ? " FAIL" : " OK")
+   (fontID < 0 ? " FAIL" : " OK")
<< endl;
}
 #endif
@@ -221,19 +219,6 @@
 }
 
 
-GuiFontLoader::~GuiFontLoader()
-{
-#if QT_VERSION >= 0x040200
-   for (int i = 0 ; i < num_math_fonts; ++i) {
-   if (fontID[i] >= 0)
-   QFontDatabase::removeApplicationFont(fontID[i]);
-   }
-
-   delete [] fontID;
-#endif
-}
-
-
 void GuiFontLoader::update()
 {
for (int i1 = 0; i1 < Font::NUM_FAMILIES; ++i1) {
Index: src/frontends/qt4/GuiFontLoader.h
===
--- src/frontends/qt4/GuiFontLoader.h   (revision 20235)
+++ src/frontends/qt4/GuiFontLoader.h   (working copy)
@@ -48,7 +48,7 @@
GuiFontLoader();
 
/// Destructor
-   ~GuiFontLoader();
+   virtual ~GuiFontLoader() {}
 
virtual void update();
virtual bool available(Font const & f);
@@ -74,9 +74,6 @@
}
 
 private:
-#if QT_VERSION >= 0x040200
-   int * fontID;
-#endif
/// BUTT ugly !
QLFontInfo * fontinfo_[Font::NUM_FAMILIES][2][4][10];
 };


Re: Lyx/branch crashes during exit.

2007-09-11 Thread Bo Peng
> I will compile with gcc 4 and try again.

Gcc4 + Qt 422 crashes.

Gcc4 + Qt 4.0 (or 4.11? not sure) does not.

Have not tested Gcc 3 + Qt 4.0, but it is likely a Qt 422 problem.

Bo


Re: Lyx/branch crashes during exit.

2007-09-11 Thread Bo Peng
> I should have said, using Qt 4.2.1, so this code is being compiled.

Then this might be another gcc 3 / signals problem. :-)

I will compile with gcc 4 and try again.

Bo


Re: Lyx/branch crashes during exit.

2007-09-11 Thread Darren Freeman
On Tue, 2007-09-11 at 22:50 -0500, Bo Peng wrote:
> #2 points to
> GuiFontLoader::~GuiFontLoader()
> {
> #if QT_VERSION >= 0x040200
>   for (int i = 0 ; i < num_math_fonts; ++i) {
>   if (fontID[i] >= 0)
>   QFontDatabase::removeApplicationFont(fontID[i]);
>   }
> 
>   delete [] fontID;
> #endif
> }

I should have said, using Qt 4.2.1, so this code is being compiled.

Have fun,
Darren



Re: Lyx/branch crashes during exit.

2007-09-11 Thread Darren Freeman
On Tue, 2007-09-11 at 22:50 -0500, Bo Peng wrote:
> On linux, simply start and quit lyx.

r20206 didn't do this. I just built r20235 and tried. Sorry but
following your procedure I don't get a crash.

OpenSUSE 10.2.

Have fun,
Darren