简体   繁体   English

SpriteKit 作为 SceneKit 的覆盖 SKShapeNode 崩溃

[英]SpriteKit as SceneKit's overlay SKShapeNode Crash

I having a strange Crash in SKOverlayScene I do not have the same crash when I am using SKScene Alone not as overlay.我在 SKOverlayScene 中发生了奇怪的崩溃 当我单独使用 SKScene 而不是覆盖时,我没有发生同样的崩溃。

This is Console output.这是控制台输出。

Edit The crash never happens if address sanitizer is available.编辑如果地址清理器可用,则不会发生崩溃。

malloc: * error for object 0x610000670e00: Invalid pointer dequeued from free list * set a breakpoint in malloc_error_break to debug malloc: * 对象 0x610000670e00 的错误:从空闲列表中出列的指针无效 *在 malloc_error_break 中设置断点以进行调试

May someone help please?有人可以帮忙吗?

Overlay SKSceme Code below:叠加 SKSceme 代码如下:

- (instancetype)initWithSize:(CGSize)size
{
    if(self = [super initWithSize:size])
    {
        //[self setBackgroundColor:[SKColor greenColor]];

        _selectionNode = [SKShapeNode node]; // iVar
        [_selectionNode setLineWidth:1];
        [_selectionNode setStrokeColor:[SKColor whiteColor]];
        [_selectionNode setFillColor:[SKColor colorWithRed:0.2 green:0.5 blue:1 alpha:0.2]];
        ///[_selectionNode setZPosition:CGFLOAT_MAX-1];
    }
    return self;
}

- (void)mouseDragged:(NSEvent *)theEvent
{
    if(_selectionNode)
    {
        dispatch_async(dispatch_get_main_queue(), ^
        {
            @autoreleasepool
            {
                CGPoint point = [theEvent locationInNode:self];
                CGRect rect = CGRectMake(_selectionOrigin.x, _selectionOrigin.y, point.x - _selectionOrigin.x, point.y - _selectionOrigin.y);

                CGPathRef path = CGPathCreateWithRect(rect, NULL);
                if(path)
                {
                    [_selectionNode setPath:path]; //SIGABRT is sometimes shown here.
                    CGPathRelease(path);
                }
            }
        });
    }
    [super mouseDragged:theEvent];
}

- (void)mouseDown:(NSEvent *)theEvent
{
    if(_selectionNode)
    {
        dispatch_async(dispatch_get_main_queue(), ^
        {
            [self addChild:_selectionNode];
            _selectionOrigin = [theEvent locationInNode:self];
        });
    }

    [super mouseDown:theEvent];
}

- (void)mouseUp:(NSEvent *)theEvent
{
    if(_selectionNode)
    {
        dispatch_async(dispatch_get_main_queue(), ^
        {
            [_selectionNode removeFromParent];
            [_selectionNode setPath:nil];
        });
    }
    [super mouseUp:theEvent];
}

EDIT 2编辑 2

Setting a BreakPoint in malloc_error_break show the following在 malloc_error_break 中设置 BreakPoint 显示以下内容

libsystem_malloc.dylib`malloc_error_break: -> 0x7fffba83e147 <+0>: pushq %rbp 0x7fffba83e148 <+1>: movq %rsp, %rbp 0x7fffba83e14b <+4>: nop libsystem_malloc.dylib`malloc_error_break: -> 0x7fffba83e147 <+0>: pushq %rbp 0x7fffba83e148 <+1>: movq %rsp, %rbp 0x7fffba83e14b <+4>: nop
0x7fffba83e14c <+5>: nopl (%rax) 0x7fffba83e150 <+9>: popq %rbp 0x7fffba83e151 <+10>: retq 0x7fffba83e14c <+5>: nopl (%rax) 0x7fffba83e150 <+9>: popq %rbp 0x7fffba83e151 <+10>: retq

Coming from various threads each time.每次都来自不同的线程。

Edit 3 The crash is not recreating when using OpenGL Renderer.编辑 3使用 OpenGL 渲染器时不会重新创建崩溃。

But I really want to use Metal because it really gives twice better performance the only problem is this weird crash... is there anything I can do ?但我真的很想使用 Metal 因为它确实提供了两倍的性能,唯一的问题是这个奇怪的崩溃......我能做些什么吗?

Edit 4编辑 4

I substitute SKShapeNode with SKSpriteNode and the problem is seems to be solved.我用 SKSpriteNode 替换了 SKShapeNode,问题似乎解决了。

-- This smells like an Apple bug with: Metal SceneKit + SpriteKit and SKShapeNode. -- 这闻起来像 Apple 的 bug:Metal SceneKit + SpriteKit 和 SKShapeNode。

I won't file any bug reports since Apple just ignores my reports.我不会提交任何错误报告,因为 Apple 只是忽略了我的报告。

One thing I discovered is that using overlaySKScene in SceneKit results in a lot of random crashes like this.我发现的一件事是,在 SceneKit 中使用 overlaySKScene 会导致很多这样的随机崩溃。 Also note that when using SKScene as an overlaySKScene that call backs from actions are not on the Main Thread (whereas they are when used as a stand-alone scene).另请注意,当使用 SKScene 作为overlaySKScene 时,来自动作的回调不在主线程上(而当它们用作独立场景时)。

My solution was to use a normal SKScene.我的解决方案是使用普通的 SKScene。 Just add an SKView as a subview to your SCNScene and call presentScene to use SKScene in the normal way.只需将 SKView 作为子视图添加到您的 SCNScene 并调用 presentScene 以正常方式使用 SKScene。 That stopped the crashing for me.这阻止了我的崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM