簡體   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