I have a function which I use for generating thumbnails for the UI, but when I call it from multiple threads I get memory access errors in TheManager->Load() . I tried locking it with both Win32 critical sections and Qmutex, but with no success. I guess TheManager->Load() itself is not thread-safe. Is there another way?
Bitmap* Loader::loadHDR(const QString & path) { Bitmap* bmap; BitmapInfo bi; QFile file(path); if (file.exists() && file.fileName().endsWith(".exr") || file.fileName().endsWith(".hdr")) { bi.SetName(TSTR(path)); bmap = TheManager->Load(&bi); if (!bmap) { return nullptr; } return bmap; } return nullptr; }
QIcon Loader::getIcon(const QString & path, QSize size) { Bitmap* bmap = loadHDR(path); if (bmap) { BitmapInfo bi_icon; bi_icon.SetWidth(size.width()); bi_icon.SetHeight(size.height()); bi_icon.SetType(BMM_TRUE_32); Bitmap* icon = TheManager->Create(&bi_icon); icon->CopyImage(bmap, COPY_IMAGE_RESIZE_LO_QUALITY, BMM_Color_64(0, 0, 0, 0)); int type; uchar* buffer = static_cast<uchar*>(icon->GetStoragePtr(&type)); QImage image(buffer, icon->Width(), icon->Height(), QImage::Format::Format_RGB888); if (bmap) bmap->DeleteThis(); return QIcon(QPixmap::fromImage(image)); } return QIcon(); }
I have a function which I use for generating thumbnails for the UI, but when I call it from multiple threads I get memory access errors in TheManager->Load() . I tried locking it with both Win32 critical sections and Qmutex, but with no success. I guess TheManager->Load() itself is not thread-safe. Is there another way?
Bitmap* Loader::loadHDR(const QString & path) { Bitmap* bmap; BitmapInfo bi; QFile file(path); if (file.exists() && file.fileName().endsWith(".exr") || file.fileName().endsWith(".hdr")) { bi.SetName(TSTR(path)); bmap = TheManager->Load(&bi); if (!bmap) { return nullptr; } return bmap; } return nullptr; }
QIcon Loader::getIcon(const QString & path, QSize size) { Bitmap* bmap = loadHDR(path); if (bmap) { BitmapInfo bi_icon; bi_icon.SetWidth(size.width()); bi_icon.SetHeight(size.height()); bi_icon.SetType(BMM_TRUE_32); Bitmap* icon = TheManager->Create(&bi_icon); icon->CopyImage(bmap, COPY_IMAGE_RESIZE_LO_QUALITY, BMM_Color_64(0, 0, 0, 0)); int type; uchar* buffer = static_cast<uchar*>(icon->GetStoragePtr(&type)); QImage image(buffer, icon->Width(), icon->Height(), QImage::Format::Format_RGB888); if (bmap) bmap->DeleteThis(); return QIcon(QPixmap::fromImage(image)); } return QIcon(); }
I'm guessing, but...
The docs say:
Does that help?
Drew
I'm guessing, but...
The docs say:
Does that help?
Drew
The reason I was getting errors in TheManager->Load() was that the code didn't handle task cancellation. It's all working fine now.
The reason I was getting errors in TheManager->Load() was that the code didn't handle task cancellation. It's all working fine now.
Can't find what you're looking for? Ask the community or share your knowledge.