Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SKTexture EXC_坏访问_Ios_Uiimage_Sprite Kit_Cifilter_Sktexture - Fatal编程技术网

Ios SKTexture EXC_坏访问

Ios SKTexture EXC_坏访问,ios,uiimage,sprite-kit,cifilter,sktexture,Ios,Uiimage,Sprite Kit,Cifilter,Sktexture,我正在开发一款SpriteKit游戏,并试图允许用户通过着色来定制游戏中的舰船图像 我向UIImage添加了一个类别,该类别提供了adjustImage:色调:饱和度:亮度的实现。它使用两个CIFILTER进行调整。我知道该代码是有效的,因为我在另一个应用程序中使用UIImageView而不是SKTexture对其进行了测试 还要注意,CSHeroShipNode是SKSpriteNode的一个子类 出现的问题是,我在指示线路上的访问权限不好,我不知道为什么。调试表明,图像和纹理在过程中的任何地

我正在开发一款SpriteKit游戏,并试图允许用户通过着色来定制游戏中的舰船图像

我向UIImage添加了一个类别,该类别提供了adjustImage:色调:饱和度:亮度的实现。它使用两个CIFILTER进行调整。我知道该代码是有效的,因为我在另一个应用程序中使用UIImageView而不是SKTexture对其进行了测试

还要注意,CSHeroShipNode是SKSpriteNode的一个子类

出现的问题是,我在指示线路上的访问权限不好,我不知道为什么。调试表明,图像和纹理在过程中的任何地方都不会为零,即使在传递到第二个方法时也是如此

以下代码来自CSHeroShipNode类

这是坠机后的回溯

* thread #1: tid = 0xb100f, 0x0000000102c2ee3d libsystem_platform.dylib`OSSpinLockLock + 7, queue = 'com.apple.main-thread, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x0000000102c2ee3d libsystem_platform.dylib`OSSpinLockLock + 7
frame #1: 0x00000001012edaa1 SpriteKit`SKSpinLockSync(int*, void () block_pointer) + 30
frame #2: 0x00000001012b6ce7 SpriteKit`-[SKTexture loadImageData] + 221
frame #3: 0x00000001012b921f SpriteKit`-[SKTexture size] + 33
frame #4: 0x00000001012d766c SpriteKit`-[SKSpriteNode initWithTexture:] + 96
frame #5: 0x00000001012d77d8 SpriteKit`+[SKSpriteNode spriteNodeWithTexture:] + 76
frame #6: 0x00000001012d7857 SpriteKit`+[SKSpriteNode spriteNodeWithTexture:size:] + 77
frame #7: 0x0000000100006b98 Space`+[CSHeroShipNode shipWithTexture:size:](self=0x0000000100022300, _cmd=0x000000010001753b, texture=0x0000000116354ab0, size=CGSize at 0x00007fff5fbfc7d8) + 136 at CSHeroShipNode.m:27
frame #8: 0x0000000100006a3f Space`+[CSHeroShipNode heroShip](self=0x0000000100022300, _cmd=0x00000001000175c9) + 287 at CSHeroShipNode.m:22
frame #9: 0x0000000100010d3e Space`-[CSSurvivalGameLevel getHeroShip](self=0x0000000116341bf0, _cmd=0x0000000100017a14) + 46 at CSSurvivalGameLevel.m:33
frame #10: 0x00000001000152c5 Space`+[CSWorldNode worldNodeWithLevel:scene:](self=0x0000000100022a80, _cmd=0x0000000100017be7, level=0x0000000116341bf0, scene=0x000000011634d490) + 837 at CSWorldNode.m:24
frame #11: 0x000000010000b8d2 Space`-[CSGameScene initWithSize:level:](self=0x000000011634d490, _cmd=0x0000000100017b24, size=CGSize at 0x00007fff5fbfcc80, level=0x0000000116341bf0) + 1202 at CSGameScene.m:70
frame #12: 0x000000010000b3f1 Space`+[CSGameScene gameSceneWithSize:level:](self=0x0000000100022530, _cmd=0x0000000100017a64, size=CGSize at 0x00007fff5fbfcce0, level=0x0000000116341bf0) + 113 at CSGameScene.m:47
frame #13: 0x0000000100014e65 Space`-[CSMainMenuScene newGame](self=0x000000010c0154d0, _cmd=0x00000001000187c0) + 133 at CSMainMenuScene.m:44
frame #14: 0x00000001000056c1 Space`-[CSButtonNode callAction](self=0x000000010c02a280, _cmd=0x00000001000173ab) + 209 at CSButtonNode.m:41
frame #15: 0x00000001000057d1 Space`-[CSButtonNode pressEnded](self=0x000000010c02a280, _cmd=0x0000000100017413) + 129 at CSButtonNode.m:52
frame #16: 0x00000001000064a4 Space`-[CSButtonNode touchesEnded:withEvent:](self=0x000000010c02a280, _cmd=0x0000000100a00ce3, touches=0x000000011634cd50, event=0x000000010c501460) + 772 at CSButtonNode.m:81
frame #17: 0x00000001012c0df4 SpriteKit`-[SKView touchesEnded:withEvent:] + 540
frame #18: 0x00000001003a3c15 UIKit`-[UIWindow _sendTouchesForEvent:] + 701
frame #19: 0x00000001003a4633 UIKit`-[UIWindow sendEvent:] + 988
frame #20: 0x000000010037dfa2 UIKit`-[UIApplication sendEvent:] + 211
frame #21: 0x000000010036bd7f UIKit`_UIApplicationHandleEventQueue + 9549
frame #22: 0x0000000101a5fec1 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
frame #23: 0x0000000101a5f792 CoreFoundation`__CFRunLoopDoSources0 + 242
frame #24: 0x0000000101a7b61f CoreFoundation`__CFRunLoopRun + 767
frame #25: 0x0000000101a7af33 CoreFoundation`CFRunLoopRunSpecific + 467
frame #26: 0x0000000101f063a0 GraphicsServices`GSEventRunModal + 161
frame #27: 0x000000010036e043 UIKit`UIApplicationMain + 1010
frame #28: 0x0000000100016253 Space`main(argc=1, argv=0x00007fff5fbfed28) + 115 at main.m:16
frame #29: 0x0000000102c255fd libdyld.dylib`start + 1
frame #30: 0x0000000102c255fd libdyld.dylib`start + 1
编辑:这是整个CSHeroShipNode类


原来这是SpriteKit代码中的一个bug,请参见一个非常类似问题的答案。在lldb跟踪之后,我想这是一个内存管理问题,它在使用过滤器时如何分配图像数据缓冲区

最后,我在adjustImage:hue:saturation:brightness:method中使用CIContext来创建CGImageRef,然后返回它。所以CSHeroShipNode中的代码最终是这样的

+(instancetype)heroShip {
    CGImageRef textureImage = [UIImage adjustImage:[UIImage imageNamed:@"heroShip_0001.png"] hue:0.0 saturation:1.0 brightness:0.0];
    SKTexture *heroTexture = [SKTexture textureWithCGImage:textureImage];
    CSHeroShipNode *hero = [CSHeroShipNode shipWithTexture:heroTexture size:CGSizeMake(64, 64)];
    return hero;
}

虽然这种变通方法并不可怕,但我仍然觉得苹果的代码存在这样的问题很烦人。希望他们能尽快修复。

你能发布CSHeroShipNode类吗?@prototypical抱歉,我忘了提到这些方法所在的类。它中的其他内容都与此无关,因为它在崩溃后很久才被调用。您确定在调试时介入了吗?假设返回的值是问题所在?幽默我,因为崩溃日志似乎表明比您假设的更相关。我按照您的要求添加了它。在调试过程中,我将按step-into,然后它会在不进入方法的情况下给我错误的访问权限。我想那是因为它是SKSpriteNode类的一部分。
#import "CSHeroShipNode.h"

#import "CSGameScene.h"
#import "CSPhaserNode.h"

@implementation CSHeroShipNode {
    SKEmitterNode *exhaust;
}

+(instancetype)heroShip {
    UIImage *textureImage = [UIImage adjustImage:[UIImage imageNamed:@"heroShip_0001.png"] hue:0.0 saturation:1.0 brightness:0.0];
    SKTexture *heroTexture = [SKTexture textureWithImage:textureImage];
    CSHeroShipNode *hero = [CSHeroShipNode shipWithTexture:heroTexture size:CGSizeMake(64, 64)];
    return hero;
}

+(instancetype)shipWithTexture:(SKTexture *)texture size:(CGSize)size {
    CSHeroShipNode *ship = [CSHeroShipNode spriteNodeWithTexture:texture size:size];

    ship.name = @"Hero";
    ship.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:size.width / 2];
    ship.physicsBody.categoryBitMask = CSPhysicsBodyCollisionTypeHeroShip;
    ship.physicsBody.collisionBitMask = CSPhysicsBodyCollisionTypeWorld;
    ship.physicsBody.contactTestBitMask = CSPhysicsBodyCollisionTypeEnemyPhaser | CSPhysicsBodyCollisionTypeEnemyShip | CSPhysicsBodyCollisionTypeObject;

    ship->exhaust = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"Exhaust" ofType:@"sks"]];
    CGPoint exhaustPosition = CGPointMake(ship.position.x, ship.position.y - ship.size.height / 2 + 7);
    ship->exhaust.position = exhaustPosition;
    [ship addChild:ship->exhaust];

    // set the initial health
    ship.health = 200;

    ship.weaponCharge = 100;
    ship.weaponChargeRate = 100;

    return ship;
}

-(void)fireToLocation:(CGPoint)location atTime:(CFTimeInterval)gameTime {
    // delay phaser firing due to recharge time
    if (self.weaponCharge == 100) {
        lastFireTime = gameTime;
        self.weaponCharge = 0;

        float xOffset = location.x - self.position.x;
        float yOffset = location.y - self.position.y;
        float angle = atan2f(yOffset, xOffset);

        CSPhaserNode *phaser = [[CSPhaserNode alloc] initWithPosition:self.position angle:angle time:gameTime];
        phaser.parentShip = self;
        [((CSGameScene *)self.scene).world addChild:phaser];
    }
}

-(void)takeDamage:(NSUInteger)damage {
    self.health -= damage;
}

-(void)die {
    // make sure that health is 0
    self.health = 0;
    // create an explosion for the ship
    SKEmitterNode *explosion = [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"ShipExplosion" ofType:@"sks"]];
    explosion.position = self.position;
    [((CSGameScene *)self.scene).world addChild:explosion];
    [self removeFromParent];
}

-(void)update:(CFTimeInterval)gameTime {
    [super update:gameTime];
}


@end
+(instancetype)heroShip {
    CGImageRef textureImage = [UIImage adjustImage:[UIImage imageNamed:@"heroShip_0001.png"] hue:0.0 saturation:1.0 brightness:0.0];
    SKTexture *heroTexture = [SKTexture textureWithCGImage:textureImage];
    CSHeroShipNode *hero = [CSHeroShipNode shipWithTexture:heroTexture size:CGSizeMake(64, 64)];
    return hero;
}