ios - Reading CGImageRef in a background thread crashes the app -


i have big jpeg image want load in tiles asynchronously in opengl engine. works if done on main thread slow.

when try put tile loading on nsoperationblock, crashes when trying access shared image data pointer loaded on main thread.

there must don't background operation because assume can access memory sections created on main thread.

what try following :

@interface myviewer { } @property (atomic, assign) cgimageref imageref; @property (atomic, assign) cgdataproviderref dataprovider; @property (atomic, assign) int loadedtextures; @end  ...  - (void) loadalltiles:(nsdata*) imgdata {     queue = [[nsoperationqueue alloc] init];     //loop total number of textures      self.dataprovider = cgdataprovidercreatewithdata(null,[imgdata bytes],[imgdata length],0);     self.imageref = cgimagecreatewithjpegdataprovider(self.dataprovider, null, no, kcgrenderingintentdefault);      (int i=0; i<tilecount; i++)     {         // tried without luck        //cgimageretain(self.imageref);        //cgdataproviderretain(self.dataprovider);          nsblockoperation *partsloading = [[nsblockoperation alloc] init];         __weak nsblockoperation *weakpartsloadingop = partsloading;         [partsloading addexecutionblock: ^ {              tamtexture2d& ptex2d = viewer->gettile(i);              cgimageref subimgref = cgimagecreatewithimageinrect(self.imageref, cgrectmake(ptex2d.left, ptex2d.top, ptex2d.width, ptex2d.height));              //!!!its crashing here!!!             cfdataref cgsubimgdataref = cgdataprovidercopydata(cgimagegetdataprovider(subimgref));             cgimagerelease(subimgref);              ...             }];          //adding parts loading on low priority thread. right ????         [partsloading setthreadpriority:0.0];         [queue addoperation:partsloading];  } 

i found out problem...

i have read quartz2d doc , seems should not use cgdataprovidercreatewithdata , cgimagecreatewithjpegdataprovider anymore. guess there usage not thread safe.

as suggested doc, use cgimagesource api :

self.imagesrcref = cgimagesourcecreatewithdata((__bridge cfdataref)imgdata, null);  // imagepropertiesdictionary cfdictionaryref imagepropertiesdictionary = cgimagesourcecopypropertiesatindex(m_imagesrcref,0, null);  self.imageref = cgimagesourcecreateimageatindex(m_imagesrcref, 0, imagepropertiesdictionary); 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -