繁体   English   中英

Magick ++段错误在线程中

[英]Magick++ segfaults in thread

编写扫描程序。 在读取图像后,它调用convertToPDF()然后读取下一个图像。 当在线程中声明Image时,程序seg fault( RUN FINISHED; Segmentation fault: 11; )。 在主线程中运行时,相同的代码工作正常,我将它从thrPDF移动到convertToPDF以确保。 所以我认为这与Magick ++的内存分配有关。 任何帮助将非常感激。

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);
}

这是调用堆栈:
omp_get_max_threads(?)
GetOpenMPMaximumThreads内联
AcquirePixelCache(?)
AcquireImage(?)
Magick :: ImageRef :: ImageRef(?)
Magick ::图像::图像(?)
thrPDF(?)
_pthread_start(?)
thread_start(?)

如果尚未完成,则应在使用其余API之前在主/原始线程中调用InitializeMagick(NULL)(或InitializeMagick(* argv))。 这可能有助于解决与线程相关的一些问题。 随着GraphicsMagick中包含Magick ++,这是现代版本中的绝对要求。

暂无
暂无

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

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