exception during string assignment from GDCM

0

I have a Qt application that I am building with newer versions of VC++ and GDCM. I had built the application previously with VC++ 2015, and old version of GDCM, and it compiled and ran just fine. Now I'm running into an exception in a string assignment.

gdcm::Reader r;
r.SetFileName(f.toStdString().c_str());
if (r.Read()) {
    gdcm::StringFilter sf;
    sf = gdcm::StringFilter();
    sf.SetFile(r.GetFile());
    std::string s;

    /* get modality */
    gdcm::Tag tag = gdcm::Tag(0x0008,0x0060);
    s = sf.ToString(tag); // <-- runtime error here...
    fileModality = QString(s.c_str());

    /* get patientID */
    s = sf.ToString(gdcm::Tag(0x0010,0x0020));
    filePatientID = QString(s.c_str());

    /* get protocol (seriesDesc) */
    s = sf.ToString(gdcm::Tag(0x0008,0x103E));
    fileProtocol = QString(s.c_str());
}

If I use the assign function, the error moves to the next line, in the conversion from a string to a c_str.

s.assign(sf.ToString(tag));
fileModality = QString(s.data());

I'm not sure what's going on, but it seems to be an issue with GDCM not properly returning a string object.

Edit: The error is a dialog box with the following

The inferior stopped because it triggered an exception.
Stopped in thread 0 by: Exception at 0x7ffaa7b8f621, code: 0xc0000005: read access violation at: 0xfffffffffff, flags=0x0 (first chance).

And the call stack, starting with my own function call

1   std::_Container_base12::_Swap_all                                                 xutility           239  0x7ff7764a7b7a 
2   std::_String_alloc<std::_String_base_types<char,std::allocator<char>>>::_Swap_all xstring            2029 0x7ff7764a7af7 
3   std::string::_Assign_rv_contents_with_alloc_always_equal                          xstring            2353 0x7ff7764a619d 
4   std::string::_Assign_rv_contents                                                  xstring            2326 0x7ff7764a6132 
5   std::string::operator=                                                            xstring            2308 0x7ff7764a37cd 
6   MainWindow::GetFileType                                                           mainwindow.cpp     477  0x7ff77648784c 
... <More>                                                                                                                   
c++
qt
gdcm
asked on Stack Overflow Feb 28, 2019 by Greg B • edited Feb 28, 2019 by Greg B

1 Answer

0

I'm putting this here in case anyone encounters a similar problem.

I was able to figure out the problem. GDCM was compiled in Release... but my application was compiled in Debug. Somehow it linked just fine and mostly ran, but when it encountered a function call from the GDCM library, it crashed. Compiling everything in Release or Debug fixed it.

answered on Stack Overflow Feb 28, 2019 by Greg B

User contributions licensed under CC BY-SA 3.0