简体   繁体   中英

Magick++ segfaults in thread

Writing a scanning program. After it reads an image, it calls convertToPDF() and then reads the next image. The program seg faults ( RUN FINISHED; Segmentation fault: 11; ) when the Image is declared in the thread. The same code works fine when run in the main thread, I moved it from thrPDF to convertToPDF to make sure. So I'm thinking it's something to do with Magick++'s memory allocation that is over my head. Any help would be much appreciated.

void ScanWindow::convertToPDF(string fileName)
{
   pthread_t convert;
   string* args = new string(fileName);
   void *thrPDF(void*);
   pthread_create(&convert,NULL,thrPDF,args);
}

void *thrPDF(void* a)
{
   string* fName = (string*) a;
   string newFile = fName->substr(0,fName->length()-3) + "pdf";

   Magick::Image img(*fName);  // this is the line that seg faults
   img.magick("pdf");
   img.write(newFile);

   pthread_exit(0);
}

Here is the call stack:
omp_get_max_threads(?)
GetOpenMPMaximumThreads inlined
AcquirePixelCache(?)
AcquireImage(?)
Magick::ImageRef::ImageRef(?)
Magick::Image::Image(?)
thrPDF(?)
_pthread_start(?)
thread_start(?)

If it is not already being done, you should be invoking InitializeMagick(NULL) (or InitializeMagick(*argv)) in your main/original thread prior to using the rest of the API. This may help cure some issues related to threading. With Magick++ included with GraphicsMagick, this is an absolute requirement in modern releases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM