Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit daa0956f authored by Scott Wheeler's avatar Scott Wheeler

Fixed a segfault that was occuring by using locate() in the initialization

of a static data member.  This caused problems because KApplication hasn't
started yet when static members are initialized and so it can't provide
the application name to locate.

svn path=/trunk/kdemultimedia/juk/; revision=141262
parent 3b69f66d
......@@ -24,18 +24,15 @@
// public members
////////////////////////////////////////////////////////////////////////////////
GenreList::GenreList()
GenreList::GenreList(bool createIndex = false)
{
// index = 0;
hasIndex = createIndex;
}
GenreList::GenreList(QString file, bool createIndex = false)
{
// index = 0;
hasIndex = createIndex;
load(file);
if(createIndex)
initializeIndex();
}
GenreList::~GenreList()
......@@ -50,11 +47,14 @@ void GenreList::load(QString file)
QXmlSimpleReader reader;
reader.setContentHandler(handler);
reader.parse(source);
if(hasIndex)
initializeIndex();
}
QString GenreList::name(int id3v1)
{
if(id3v1 >= 0 && id3v1 < int(index.size()))
if(hasIndex && id3v1 >= 0 && id3v1 < int(index.size()))
return(index[id3v1]);
else
return(QString::null);
......@@ -66,6 +66,7 @@ QString GenreList::name(int id3v1)
void GenreList::initializeIndex()
{
kdDebug() << "initializeIndex()" << endl;
index.clear();
index.resize(count());
for(GenreList::Iterator it = begin(); it != end(); ++it) {
......
......@@ -27,7 +27,7 @@
class GenreList : public QValueList<Genre>
{
public:
GenreList();
GenreList(bool createIndex = false);
GenreList(QString file, bool createIndex = false);
~GenreList();
......@@ -37,6 +37,7 @@ public:
private:
QValueVector<QString> index;
bool hasIndex;
void initializeIndex();
};
......
......@@ -23,14 +23,24 @@
// static members
////////////////////////////////////////////////////////////////////////////////
// There are some nasty hacks here to get around not being able to call locate()
// in the initialization of a static data member. As a result, the function
// below can not be called in the initialization of another static member and
// if it is, well, all hell will break loose and you'll get a strange segfault.
// public
GenreList GenreListList::id3v1List()
{
if(!id3v1Loaded) {
id3v1.load(locate("data", "juk/id3v1.genreml"));
id3v1Loaded = true;
}
return(id3v1);
}
// private
GenreList GenreListList::id3v1 = GenreList(locate("data", "juk/id3v1.genreml"), true);
GenreList GenreListList::id3v1(true);
bool GenreListList::id3v1Loaded = false;
////////////////////////////////////////////////////////////////////////////////
// public members
......
......@@ -32,6 +32,7 @@ public:
private:
static GenreList id3v1;
static bool id3v1Loaded;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment