简体   繁体   English

Magick ++段错误在线程中

[英]Magick++ segfaults in thread

Writing a scanning program. 编写扫描程序。 After it reads an image, it calls convertToPDF() and then reads the next image. 在读取图像后,它调用convertToPDF()然后读取下一个图像。 The program seg faults ( RUN FINISHED; Segmentation fault: 11; ) when the Image is declared in the thread. 当在线程中声明Image时,程序seg fault( RUN FINISHED; Segmentation fault: 11; )。 The same code works fine when run in the main thread, I moved it from thrPDF to convertToPDF to make sure. 在主线程中运行时,相同的代码工作正常,我将它从thrPDF移动到convertToPDF以确保。 So I'm thinking it's something to do with Magick++'s memory allocation that is over my head. 所以我认为这与Magick ++的内存分配有关。 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(?) omp_get_max_threads(?)
GetOpenMPMaximumThreads inlined GetOpenMPMaximumThreads内联
AcquirePixelCache(?) AcquirePixelCache(?)
AcquireImage(?) AcquireImage(?)
Magick::ImageRef::ImageRef(?) Magick :: ImageRef :: ImageRef(?)
Magick::Image::Image(?) Magick ::图像::图像(?)
thrPDF(?) thrPDF(?)
_pthread_start(?) _pthread_start(?)
thread_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. 如果尚未完成,则应在使用其余API之前在主/原始线程中调用InitializeMagick(NULL)(或InitializeMagick(* argv))。 This may help cure some issues related to threading. 这可能有助于解决与线程相关的一些问题。 With Magick++ included with GraphicsMagick, this is an absolute requirement in modern releases. 随着GraphicsMagick中包含Magick ++,这是现代版本中的绝对要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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