我在 CCscene UserLevelCreation 上切换场景(甚至显示精灵)时遇到了一点问题,但它只发生在我使用 UIImagePickerController 拍摄/接受图片之后,然后当我尝试切换场景时,它会因错误而崩溃:
"Could not attach texture to framebuffer"
这是我用来拍照的代码:
-(void)takePhoto{
AppController *appdel = (AppController*) [[UIApplication sharedApplication] delegate];
@try {
uip = [[UIImagePickerController alloc] init] ;
uip.sourceType = UIImagePickerControllerSourceTypeCamera;
uip.allowsEditing = YES;
uip.delegate = self;
}
@catch (NSException * e) {
uip = nil;
}
@finally {
if(uip) {
[appdel.navController presentModalViewController:uip animated:NO];
}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString * LevelImage;
LevelImage=[info objectForKey:UIImagePickerControllerOriginalImage];
AppController *appdel = (AppController*) [[UIApplication sharedApplication] delegate];
[appdel.navController dismissModalViewControllerAnimated:YES];
[NSThread detachNewThreadSelector:@selector(writeImgToPath:) toTarget:self withObject:LevelImage];
}
和 WriteImageToPath 函数:
-(void)writeImgToPath:(id)sender
{
UIImage *image = sender;
NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
CGSize size;
int currentProfileIndex = 1;
NSString *path = [[pathArr objectAtIndex:0]
stringByAppendingPathComponent:[NSString stringWithFormat:@"CustomLevel_%d.png",currentProfileIndex]];
size = CGSizeMake(1136, 640);
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, 1136, 640)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
CCLOG(@"saved...");
CGRect r = CGRectMake(0, 0, 1136, 640);
UIGraphicsBeginImageContext(r.size);
UIImage *img1;
[image drawInRect:r];
img1 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(img1, nil, nil, nil);
currentProfileIndex++;
[[CCDirector sharedDirector] replaceScene:[LevelEditor Scene]
withTransition:[CCTransition transitionPushWithDirection:CCTransitionDirectionLeft duration:1.0f]];
}
-更新 - - - - - - - - - - - - - - - - - - - - - - - - ---------------------------------- 刚才试过在代码中不同地方切换场景,可以切换场景自由直到功能:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
我认为该功能可能是问题所在。
到目前为止,我已经尝试过:
1.拍照前切换场景,效果很好
2.我读到这可能是因为我正在调整图像的大小,但评论出来并没有什么不同。
3.我在场景切换前也加了断点,场景不为零
4.Finally我tred解散了uip UIImagePickerController,但这也没有什么区别。
很抱歉,很长的帖子/:如果有人知道发生了什么,任何帮助都会非常棒。