2011-06-26 41 views
0

我見過帖子,NSDictionary丟失數據,但在我的情況下,它有點奇怪。我有一個包含一些數據的類,包括NSString和NSIntegers和GLfloats。 (據我所知,所有這些都符合NSCopying,不像CGFloat之類的東西)。NSDictionary丟失數據?

我在我的應用程序中快速訪問文件,它一切正常,但我嘗試再次訪問它(重新加載/刷新)屏幕,然後NSInteger值返回180000之間的東西,幾十億的價值,我知道肯定是4,所以由於某種原因,數據沒有堅持。

感覺好像數據正在丟失/釋放/改變,但我不知道它可能如何。

編輯:

赫雷什一些代碼,這是被創建,其中texturedQuads和存儲,該方法被稱爲用於每個圖譜我在init方法

此外,我已經改變其中I濫用字包裝

-(void)loadAtlasData:(NSString *)atlasName 
{ 
    NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init]; 
    if (quadLibrary == nil) 
     quadLibrary = [[NSMutableDictionary alloc] init]; 

    CGSize atlasSize = [self loadTextureImage:[atlasName 
        stringByAppendingPathExtension:@"png"] 
            materialKey:atlasName]; 

    NSArray *itemData = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:atlasName ofType:@"plist"]]; 

    for(NSDictionary *record in itemData) 
    { 
     TexturedQuad *quad = [self texturedQuadFromAtlasRecord:record 
                atlasSize:atlasSize 
                materialKey:atlasName]; 
     [quadLibrary setObject:quad forKey: 
     [record objectForKey:@"name"]]; 
    } 
    [apool release]; 
} 

-(TexturedQuad *)texturedQuadFromAtlasRecord:(NSDictionary *)record 
            atlasSize:(CGSize)atlasSize 
           materialKey:(NSString *)key 
{ 
    TexturedQuad *quad = [[TexturedQuad alloc] init]; 

    GLfloat xLocation = [[record objectForKey:@"xLocation"] floatValue]; 
    GLfloat yLocation = [[record objectForKey:@"yLocation"] floatValue];  
    GLfloat width = [[record objectForKey:@"width"] floatValue]; 
    GLfloat height = [[record objectForKey:@"height"] floatValue]; 

    //find the normalized texture co-ordinates 
    GLfloat uMin = xLocation/atlasSize.width; 
    GLfloat vMin = yLocation/atlasSize.height; 
    GLfloat uMax = (xLocation + width)/atlasSize.width; 
    GLfloat vMax = (yLocation + height)/atlasSize.height; 

    quad.uvCoordinates[0] = uMin; 
    quad.uvCoordinates[1] = vMax; 

    quad.uvCoordinates[2] = uMax; 
    quad.uvCoordinates[3] = vMax; 

    quad.uvCoordinates[4] = uMin; 
    quad.uvCoordinates[5] = vMin; 

    quad.uvCoordinates[6] = uMax; 
    quad.uvCoordinates[7] = vMin; 

    quad.materialKey = key; 

    return [quad autorelease]; 
} 

第二個編輯:

添加plist文件的例子

dict 
(key)name 
(string)sync 
(key)xLocation 
(integer)489 
(key)yLocation 
(integer)36 
(key)width 
(integer)21 
(key)height 
(integer)21 
/dict 

本質上,它是一個由字典組成的數組,每個字典都包含圖集的圖片數據。所以theres名稱,xLocation,yLocation,寬度,高度。

編輯3: 這裏是我從 加載對象我使用[MaterialController sharedMaterialController]得到這個控制器

-(TexturedQuad *)quadFromAtlasKey:(NSString *)atlasKey 
{ 
    return [quadLibrary objectForKey:atlasKey]; 
} 
+3

沒有人會有很多沒有代碼的幫助你的機會。發佈你正在談論的內容的代碼。 –

+1

另外,是否有任何理由讓你自定義包裝類而不是'NSValue'? – jtbandes

+0

我跳過了代碼,因爲它遍佈整個地方,但我現在將其添加,並且我不知道我是否打算使用單詞包裝器,但它存儲着質感的四邊形所以它存儲了大量的NSIntegers而不是抱歉。 – MPainter

回答

2

看看刪除自動釋放池排序問題的一個實例。至於我可以看到作爲quadLibrary似乎是伊娃,而的ItemData是自動釋放了它的父類,因爲都是TextureQuads你在for循環返回你不需要它。

+0

非常感謝,我認爲我把自動釋放池用於擺脫我創建的四邊形(就像它添加到字典時一樣,根據我的知識進行復制),這樣它就不會浪費內存。 – MPainter