科科斯3D崩溃,它说它无法加载纹理

时间:2012-11-29 18:36:40

标签: 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 = [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 所以下载和写东西...... 模拟器只是崩溃了。 有任何想法吗?如果您需要,请询问其他信息。 非常感谢,我很抱歉这篇长篇文章。

0 个答案:

没有答案