Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
906 views
in Technique[技术] by (71.8m points)

swift - SKTextureAtlas no longer sharing textures in iOS 10

It seems that when pulling textures from a texture atlas, I am now generating new textures instead of using the same texture across different sprites with iOS 10. On iOS 9, this works as expected. Is anyone else experiencing this issue? Perhaps there is a step I missed that is now a part of iOS 10.

Notes: I created a sample project and created a new atlas, then just dragged spaceship in @1x, I have also tried preloading, and that did nothing as well.

Code:

  let atlas = SKTexturAtlas(named:"Sprites")
  var texture = atlas.textureNamed("Spaceship")
  print("(Unmanaged.passUnretained(texture)),(Unmanaged.passUnretained(texture).toOpaque())")

  texture = atlas.textureNamed("Spaceship")
  print("(Unmanaged.passUnretained(texture)),(Unmanaged.passUnretained(texture).toOpaque())")

Edit: To get around issues of comparison, I use the description property to compare if 2 textures are equal. For this to work though, you can't be using 2 atlases that each contain a texture with an exact name and size. I will never hit this situation, but for anybody out there looking for help, keep this in mind.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've make the same test and get your same results.

I'm not sure 100% but seems that during the development of Swift 3 there was a proposal here to change Unmanaged to use UnsafePointer.

But if you try to make:

func address<T: AnyObject>(o: T) -> String{
     let addr = unsafeBitCast(o, to: Int.self)
     return NSString(format: "%p", addr) as String
}

Usage:

print(address(o: texture))

in iOS9 you have correct values, in iOS10 wrong results.

enter image description here

I think you're right, we are facing a bug (another..)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...