Dictionary problems for Objective C (NSNumber +NumberWithInt) -


in writting dictionary cg thumbnail creation, if map value directly int works perfectly:

 nsdictionary* d = [nsdictionary dictionarywithobjectsandkeys:                        (id)kcfbooleantrue, kcgimagesourceshouldallowfloat,                        (id)kcfbooleantrue, kcgimagesourcecreatethumbnailwithtransform,                        (id)kcfbooleantrue, kcgimagesourcecreatethumbnailfromimagealways,                        [nsnumber numberwithint:56], kcgimagesourcethumbnailmaxpixelsize,                        nil]; . . . . . cgimageref imref = cgimagesourcecreatethumbnailatindex(src, 0, (cfdictionaryref)d); 

now want able change value (56) property can change in interface create int in header

my.h int thumbsize;  //within init method iinitialize it:         thumbsize = 56; //then change reference in dictionary:      nsdictionary* d = [nsdictionary dictionarywithobjectsandkeys:                        (id)kcfbooleantrue, kcgimagesourceshouldallowfloat,                        (id)kcfbooleantrue, kcgimagesourcecreatethumbnailwithtransform,                        (id)kcfbooleantrue, kcgimagesourcecreatethumbnailfromimagealways,                        [nsnumber numberwithint:thumbsize], kcgimagesourcethumbnailmaxpixelsize,                        nil]; 

if this, crashes following error:

 mar 25 11:39:49 charles-romestants-macbook.local photomosaic[3583] : imageio: cgimagesourcecreatewithdata data parameter nil mar 25 11:39:49 charles-romestants-macbook.local photomosaic[3583] : imageio: cgimagesourcecreateimageatindex image source parameter nil 2013-03-25 11:39:49.197 photomosaic[3583:707] *** -[__nsarraym insertobject:atindex:]: object cannot nil 2013-03-25 11:39:49.201 photomosaic[3583:707] (     0   corefoundation                      0x00007fff912ccb06 __exceptionpreprocess + 198     1   libobjc.a.dylib                     0x00007fff8bc833f0 objc_exception_throw + 43     2   corefoundation                      0x00007fff9127d27a -[__nsarraym insertobject:atindex:] + 282     3   photomosaic                         0x00000001000023bf -[blendingview setmosaicimages:] + 1071     4   photomosaic                         0x0000000100003034 -[controller createmosaic:] + 84     5   appkit                              0x00007fff8ec3d989 -[nsapplication sendaction:to:from:] + 342     6   appkit                              0x00007fff8ec3d7e7 -[nscontrol sendaction:to:] + 85     7   appkit                              0x00007fff8ec3d71b -[nscell _sendactionfrom:] + 138     8   appkit                              0x00007fff8ec3bc03 -[nscell trackmouse:inrect:ofview:untilmouseup:] + 1855     9   appkit                              0x00007fff8ec3b451 -[nsbuttoncell trackmouse:inrect:ofview:untilmouseup:] + 504     10  appkit                              0x00007fff8ec3abcc -[nscontrol mousedown:] + 820     11  appkit                              0x00007fff8ec3253e -[nswindow sendevent:] + 6853     12  appkit                              0x00007fff8ec2e674 -[nsapplication sendevent:] + 5761     13  appkit                              0x00007fff8eb4424a -[nsapplication run] + 636     14  appkit                              0x00007fff8eae8c06 nsapplicationmain + 869     15  photomosaic                         0x0000000100001d52 main + 34     16  photomosaic                         0x0000000100001d24 start + 52 )  

why this, i'm passing nsnumber +numberwithint int...

[edit] adding whole method:

-(void)setmosaicimages:(nsmutablearray *)_mosaicimages {     nslog(@"entering here in setmosaicimages, have %lu images",_mosaicimages.count);     mosaicimages = _mosaicimages;     cgimagesourceref source;      source = cgimagesourcecreatewithdata((cfdataref)[canvasimage tiffrepresentation], null);     cgimageref image =  cgimagesourcecreateimageatindex(source, 0, null);     cgcolorspaceref colorspace = cgcolorspacecreatedevicergb();     cgcontextref ctx = cgbitmapcontextcreate(null,                                              cgimagegetwidth(image), cgimagegetheight(image),                                              8, cgimagegetwidth(image) * 4,                                              colorspace, kcgimagealphapremultipliedlast);     cgcolorspacerelease(colorspace);      nsdictionary* d = [nsdictionary dictionarywithobjectsandkeys:                        (id)kcfbooleantrue, kcgimagesourceshouldallowfloat,                        (id)kcfbooleantrue, kcgimagesourcecreatethumbnailwithtransform,                        (id)kcfbooleantrue, kcgimagesourcecreatethumbnailfromimagealways,                        [nsnumber numberwithint:thumbsize], kcgimagesourcethumbnailmaxpixelsize,                        nil];  //thumbsize declared in.h , initialized in init method value of 56 (int thumbsize; thumbsize = 56; if change parameter literal 56 works.     //create nsmutable array thumbnails each mosaic image     mosaiccgthumbs = [[nsmutablearray alloc]initwithcapacity:mosaiccgthumbs.count];     nsurl* url;     for(int i=0; i<mosaicimages.count;i++)     {         url = [nsurl fileurlwithpath:[(myimageobject *)[mosaicimages objectatindex:i] getpath]];         cgimagesourceref src = cgimagesourcecreatewithurl((cfurlref)url, null);         cgimageref imref = cgimagesourcecreatethumbnailatindex(src, 0, (cfdictionaryref)d);         [mosaiccgthumbs addobject:imref];         cgimagerelease(imref);      }     cgrect r;     cgimageref thumbref;     int x_offset=0;     int y_offset = 0;     while(y_offset < cgimagegetheight(image))     {         while (x_offset<cgimagegetwidth(image))         {             thumbref = (cgimageref)[mosaiccgthumbs objectatindex:arc4random() % mosaiccgthumbs.count];             r = cgrectmake(x_offset, y_offset, cgimagegetwidth(thumbref), cgimagegetheight(thumbref));             cgcontextsetblendmode(ctx, kcgblendmodecopy);             cgcontextdrawimage(ctx, r, thumbref);              x_offset+=cgimagegetwidth(thumbref);         }         x_offset=0;         y_offset+=56;     }     nslog(@"finished drawing mosaic bg");      image = cgbitmapcontextcreateimage(ctx);     //     //    ciimage* newimage = [[[ciimage alloc] initwithcgimage:image] autorelease];     //    cgimagerelease(image);     cgcontextrelease(ctx);     canvasimage = [[nsimage alloc] initwithcgimage:image size:nszerosize];     mosaicpresent=yes;     [self setneedsdisplay:yes];    } 

adding more information debugging purposes:

i decided see different created nsdictionary, so

i added following code, , breakpoint inspect:

    nsdictionary* d = [nsdictionary dictionarywithobjectsandkeys:                    (id)kcfbooleantrue, kcgimagesourceshouldallowfloat,                    (id)kcfbooleantrue, kcgimagesourcecreatethumbnailwithtransform,                    (id)kcfbooleantrue, kcgimagesourcecreatethumbnailfromimagealways,                    [nsnumber numberwithint:thumbsize], kcgimagesourcethumbnailmaxpixelsize,                    nil];  nsdictionary* d2 = [nsdictionary dictionarywithobjectsandkeys:                    (id)kcfbooleantrue, kcgimagesourceshouldallowfloat,                    (id)kcfbooleantrue, kcgimagesourcecreatethumbnailwithtransform,                    (id)kcfbooleantrue, kcgimagesourcecreatethumbnailfromimagealways,                    [nsnumber numberwithint:56], kcgimagesourcethumbnailmaxpixelsize,                    nil]; 

looking @ debugger this: (see how 2 differ in value,of pixel size thumbneail. more this.

 (gdb) po d {     kcgimagesourcecreatethumbnailfromimagealways = 1;     kcgimagesourcecreatethumbnailwithtransform = 1;     kcgimagesourceshouldallowfloat = 1;     kcgimagesourcethumbnailmaxpixelsize = 0; } (gdb) po d2 {     kcgimagesourcecreatethumbnailfromimagealways = 1;     kcgimagesourcecreatethumbnailwithtransform = 1;     kcgimagesourceshouldallowfloat = 1;     kcgimagesourcethumbnailmaxpixelsize = 56; } 

are thumbsize 56 when code executed? seems unlikely.

i see in pastebin have both -init , -initwithframe: method. if you're initializing object -initwithframe:, -init method not being called, , hence not setting value of thumbsize. odd quirk (imo; others may disagree) standard implementation of -initwithframe: not call -init.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -