Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

c++ - TagLib - Segfault when fetching tag

I'm using TagLib to get tags from audio files for my application that I'm making using wxWidgets. I have set it up to fetch multiple tags like artist, title, album and all, some files load fine, but some when loaded crashes my application and gives error saying,

./build.sh: line 12:  5891 Segmentation fault      ./SampleBrowser

I tried running with GDB,

Thread 1 "SampleBrowser" received signal SIGSEGV, Segmentation fault.
Browser::AddSamples (this=0x555555a73e00, file=...) at ../src/Browser.cpp:248
248         std::string Artist = File.tag()->artist().to8Bit(true);
(gdb)

Here is the function that is responsible for fetching tags,

void Browser::AddSamples(wxString file)
{
    TagLib::FileRef File (file);

    std::string Artist = File.tag()->artist().to8Bit(true);
    std::string Album = File.tag()->album().to8Bit(true);
    std::string Genre = File.tag()->genre().to8Bit(true);
    std::string Title = File.tag()->title().to8Bit(true);
    std::string Comment = File.tag()->comment().to8Bit(true);

    std::string Path = file.ToStdString();
    std::string Filename = file.AfterLast('/').BeforeLast('.').ToStdString();

    int Bitrate = File.audioProperties()->bitrate();
    int Channels = File.audioProperties()->channels();
    int Length = File.audioProperties()->lengthInMilliseconds();
    int LengthSec = File.audioProperties()->lengthInSeconds();
    int SampleRate = File.audioProperties()->sampleRate();

    Data.clear();
    Data.push_back(false);
    Data.push_back(Filename);
    Data.push_back(Artist);
    Data.push_back(wxString::Format("%d",Channels));
    Data.push_back(wxString::Format("%d",Length));
    Data.push_back(wxString::Format("%d",SampleRate));
    Data.push_back(wxString::Format("%d",Bitrate));
    Data.push_back(Comment);

    SampleListView->AppendItem(Data);

    db.InsertSample(0, Filename, Artist, Channels, Length,
                    SampleRate, Bitrate, Comment, Path);
}

I can provide more information if needed.

question from:https://stackoverflow.com/questions/66055653/taglib-segfault-when-fetching-tag

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...