我看过NSDictionary丢失数据的帖子,但在我的情况下它有点奇怪。我有一个包含一些数据的类,包括NSString和NSIntegers以及GLfloats。 (据我所知,所有这些都符合NSCopying,不像CGFloat。)
我在我的应用程序中快速访问文件并且一切正常,但随后我尝试再次访问它(重新加载/刷新)屏幕,然后NSInteger值返回180000之间的值,以及值为几十亿的值知道肯定是4因此由于某种原因数据没有持续存在。
感觉数据在某些时候丢失/发布/更改但我不知道它可能会如何。
编辑:
下面是一些代码,这是创建和存储texturesQuads的地方,我在init方法中为每个地图集调用该方法
此外,我改变了我滥用单词包装器的地方
-(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
本质上是一个由字典组成的数组,每个字典都包含图集中图片的数据。所以名称,xLocation,yLocation,width,height。
编辑3: 这是我加载对象的地方 我使用[MaterialController sharedMaterialController]来获取此控制器的实例
-(TexturedQuad *)quadFromAtlasKey:(NSString *)atlasKey
{
return [quadLibrary objectForKey:atlasKey];
}
答案 0 :(得分:2)
查看删除自动释放池是否排序问题。据我所知,你不需要它,因为 quadLibrary 似乎是一个iVar,而 itemData 是由其父类自动发布的,就像所有一样> TextureQuads 在 for循环中返回。