Ios Cocos3D崩溃了,它说它不能加载纹理
我必须下载一个.pod文件和一个包含纹理图像的文件夹。 之后,我必须加载pod文件,我会看到一个漂亮的3D图像Ios Cocos3D崩溃了,它说它不能加载纹理,ios,3d,cocos3d,Ios,3d,Cocos3d,我必须下载一个.pod文件和一个包含纹理图像的文件夹。 之后,我必须加载pod文件,我会看到一个漂亮的3D图像 //podNr is the id of the pod. NSString *url2 = @"http://(MY URL FOR POD FILE); NSString *urlIm2 = @"http:(MY URL FOR TEXTURE FOLDER); NSURL *Url = [NSURL URLWithString:url2]; NSURL *UrlIm = [NS
//podNr is the id of the pod.
NSString *url2 = @"http://(MY URL FOR POD FILE);
NSString *urlIm2 = @"http:(MY URL FOR TEXTURE FOLDER);
NSURL *Url = [NSURL URLWithString:url2];
NSURL *UrlIm = [NSURL URLWithString:urlIm2];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *podFile = [NSString stringWithFormat:@"PODFILE%d.pod",podNr];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:podFile];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/images"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; //Create folder
NSMutableData *urlData = [NSMutableData dataWithContentsOfURL:Url];
NSMutableData *urlImageData = [NSMutableData dataWithContentsOfURL:UrlIm];
NSString *folder = [NSString stringWithContentsOfURL:UrlIm encoding:NSUTF8StringEncoding error:nil];
NSLog(@"FOLDER CONTENT:%@",folder);
if (folder != nil) {
[self getImages:folder andpodNr:podNr];
}
NSLog(@"urlIMAGE:%d",[urlImageData length]);
[urlData writeToFile:filePath atomically:YES];
NSLog(@"sucsesfully written to file:%d",[urlData length]);
[self addContentFromPODFile: filePath];
以下是addImages函数的代码:
-(NSMutableArray*) getImages:(NSString *)html andpodNr:(int)podNr
{
NSMutableArray *outPut = [NSMutableArray alloc];
NSString *S = html;
NSString *rest;
while(TRUE)
{
if ([S rangeOfString:@".jpg\""].location == NSNotFound) {
return outPut;
}
else {
//existe .jpg!
int jpgPos = 0;
int rangeOfCom = 0;
NSString *auxS = S;
while (TRUE) {
jpgPos = [auxS rangeOfString:@".jpg\""].location;
rangeOfCom = [auxS rangeOfString:@"\""].location;
if (rangeOfCom == NSNotFound) {
return outPut;
}
if (rangeOfCom > jpgPos) {
break;
}
else {
auxS = [auxS substringFromIndex:rangeOfCom+1];
}
}
NSString *result = [auxS substringToIndex:rangeOfCom];
rest = [auxS substringFromIndex:rangeOfCom+1];
NSLog(@"RESULT:%@",result);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *newResult = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *newPath = [NSString stringWithFormat:@"/images/%@",newResult];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:newPath];
NSString *urlIm2 = @"http://(MY URL FOR IMAGES);
NSLog(@"URL:%@",urlIm2);
NSURL *urlA = [NSURL URLWithString:urlIm2];
NSMutableData *imgData = [NSMutableData dataWithContentsOfURL:urlA];
[imgData writeToFile:filePath atomically:YES];
NSLog(@"Written %d to %@",[[NSMutableData dataWithContentsOfFile:filePath] length],filePath);
}
S = rest;
}
return outPut;
以下是输出:
2012-11-29 15:12:07.324 homy2[1181:207] FOLDER CONTENT:<!DOCTYPE HTML PUBLIC "- //W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /models/1685740/m/images</title>
</head>
<body>
<h1>Index of /models/1685740/m/images</h1>
<ul><li><a href="/models/1685740/m/"> Parent Directory</a></li>
<li><a href="wood%202.jpg"> wood 2.jpg</a></li>
</ul>
</body></html>
2012-11-29 15:12:07.326 homy2[1181:207] RESULT:wood%202.jpg
2012-11-29 15:12:07.327 homy2[1181:207] URL:http://(MY URL)models/1685740/m/images/wood%202.jpg
2012-11-29 15:12:07.911 homy2[1181:207] Written 50443 to /Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/images/wood 2.jpg
2012-11-29 15:12:07.911 homy2[1181:207] urlIMAGE:315
2012-11-29 15:12:07.913 homy2[1181:207] successfully written to file:21600
2012-11-29 15:12:07.944 homy2[1181:207] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2012-11-29 15:12:07.945 homy2[1181:207] cocos2d: Couldn't add image:wood 2.jpg in CCTextureCache
2012-11-29 15:12:07.946 homy2[1181:207] [***ERROR***] CC3Texture wood%202.jpg-1 could not load texture from file wood 2.jpg
所以有几件事。。正如你所看到的,上面写着
已成功写入文件:21600
所以它是下载和写东西。。。
模拟器只是崩溃了。
有什么想法吗?如果需要,请询问其他信息。
事先非常感谢,我很抱歉发了这么长的帖子。UIImage对象为零似乎出了问题。这会发生在addContentFromPODFile中吗?@Phillip是的,会发生在那里。。奇怪的是,如果纹理的大小太大,例如4096 x 4096,那么它会显示警告:纹理大小太大,支持的大小是2048 x 2048。如果您在代码中查找此项,则警告出现在“UIIMage为nil”事件之后。所以如果它很大,它不是零,但我只是把纹理变小了…创建UIImage对象的代码是什么。。。听起来好像失败了。我不知道UIImage是在哪里创建的。。cocos3d为我做了这件事。。我只需下载所有必要的文件,然后调用addContentFromPODFile.UPDATE:我将UIImage的创建追溯到CC3TextCache,在那里调用了“addImage”方法。我创建了一个新函数addImage2,与第一个函数相同,只是替换了NSString*fullpath=[CCFileUtils fullPathFromRelativePath:path];对于简单的NSString*fullpath=path,因为我现在给出的路径是绝对的,所以它是这样的:path:/Users/demianschkolnikmuller/Library/Application Support/iPhone Simulator/4.2/Applications/685E679A-E6D9-4834-952E-9158BB37C2B9/Documents/images/wood%202.jpg现在控制台显示没有错误。。但应用程序还是崩溃了=/