gpt4 book ai didi

objective-c - SKPhysicsBody bodyWithPolygonFromPath 内存泄漏

转载 作者:太空狗 更新时间:2023-10-30 03:28:48 26 4
gpt4 key购买 nike

在创建具有自定义形状的 Sprite Kit 物理体时,我遇到了奇怪的内存泄漏问题。这是我的实现方式:

CGFloat offsetX = self.frame.size.width * self.anchorPoint.x;
CGFloat offsetY = self.frame.size.height * self.anchorPoint.y;

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 4 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(path, NULL, 66 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(path, NULL, 35 - offsetX, 57 - offsetY);
CGPathCloseSubpath(path);

self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];

CGPathRelease(path);

一切都在 SKSpriteNode 方法中进行。 Instruments 在创建这样的主体后告诉我一些内存泄漏:

Leaked object: 
Malloc 32 Bytes
Size:
32 Bytes
Responsible Library:
PhysicsKit
Responsible Frame:
std::__1::__split_buffer<PKPoint, std::__1::allocator<PKPoint>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<PKPoint>&)

CGPathRelease(path); 行是必需的 - 没有它我会得到更多关于 CGPath 的内存泄漏,这是可以理解的。当我改用此实现时(出于测试目的):

CGFloat radius = MAX(self.frame.size.width, self.frame.size.height) * 0.5f;
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:radius];

...一切正常,没有内存泄漏。我想知道这是 Sprite Kit 的错误还是我做错了什么。

最佳答案

这是 sprite 工具包中的错误。您将不得不等待修复。

关于objective-c - SKPhysicsBody bodyWithPolygonFromPath 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20134891/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com