Post marked as unsolved
693
Views
I'm trying to port a game to macOS using Mac Catalyst. The game content doesn't dynamically resize and I'm trying to force a fixed 3:4 aspect ratio (like an iPad on portrait) at the start of the app, so I've added this to my AppDelegate class:
	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if targetEnvironment(macCatalyst)
						/* some margin */
let titleHeight: CGFloat = 34 * 4
UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }.forEach { windowScene in
windowScene.titlebar?.titleVisibility = .hidden
/* screen seems to always be 1920x1080 ??? */
let height = windowScene.screen.nativeBounds.height - titleHeight
let width = 3 * height / 4
windowScene.sizeRestrictions?.minimumSize = CGSize(width: width, height: height)
windowScene.sizeRestrictions?.maximumSize = CGSize(width: width, height: height)
}
#endif
	}
That works in fixing the aspect, but the window looks small in a 15-inch MacBook Pro. nativeBounds is always 1920x1080, where the native resolution should be 1920x1200. UIScreen.main gives me 1920x1080 as well.
How can I get the real size of the screen?
Post marked as unsolved
126
Views
Every time I submit an achievement to Game Center on macOS, using Mac Catalyst, my game crashes with this:
[GKAchievementInternal showBanner]: unrecognized selector sent to instance 0x600002616ca0
No call stack. I set a break point for all the Obj-C exceptions but it's just stopped in the AppDelegate.
Everything is fine on iOS and iPadOS, and the rest of the Game Center behaviour on macOS seems to be fine.
For reference, this is how I submit the achievements:
private func submitAchievements(_ aList: [Achievement]) {
if !isGameCenterEnabled {
return
}
var achievements : [GKAchievement] = []
for kvp in AchievementFromId {
if aList.contains(kvp.1) {
let achievement = GKAchievement(identifier: kvp.0)
achievement.showsCompletionBanner = true
achievement.percentComplete = 100.0
achievements.append(achievement)
}
}
if achievements.count > 0 {
GKAchievement.report(achievements, withCompletionHandler: { (error: Error?) -> Void in
if let err = error {
NSLog("submitAchievements: \(err.localizedDescription)")
}
})
}
}
That function uses these data structures:
enum Achievement : Int {
case
clearTutorial = 0x00000001,
clearLevel1 = 0x00000002,
clearLevel2 = 0x00000004,
}
let AchievementFromId : [String : Achievement] = [
"Tutorial": .clearTutorial,
"Level1": .clearLevel1,
"Level2": .clearLevel2,
]
Also, how can I reset the achievements for one user? Because in order to debug this I already run out of chances... I need to keep creating new users in order to test the completion banner, since it's shown only once.
Post marked as unsolved
509
Views
I'm trying to resize an UIImage before I create a MTLTexture, so I first started by checking if I could initialize a MTLTexture with the CGImage obtained from the UIImage, but it always crashes with a EXC_BAD_ACCESS.This is the code that loads a UIImage,extension MTKTextureLoader {
func newTexture(with uiImage: UIImage, options: [String : NSObject]? = nil, completionHandler: @escaping MTKTextureLoaderCallback) {
if let cgImage = uiImage.cgImage {
return self.newTexture(with: cgImage, options: options, completionHandler: completionHandler)
} else {
completionHandler(nil, TextureError.CouldNotBeCreated)
}
}
}And while this code crashes,if let uiImage = UIImage(contentsOfFile: cachedFileURL.path) {
return self.newTexture(with: uiImage, options: options, completionHandler: completionHandler)
}this one works perfectly fine,return self.newTexture(withContentsOf: cachedFileURL, options: options, completionHandler: completionHandler)Shouldn't they just do the same thing?Any ideas?The call stack of the crash for reference,Thread 5Queue : com.apple.mtktextureloaderload (concurrent)
#0
0x00000001874705cc in IIOImageProviderInfo::copyImageBlockSetWithOptions(CGImageProvider*, CGRect, CGSize, __CFDictionary const*) ()
#1
0x000000018746e640 in IIOImageProviderInfo::CopyImageBlockSetWithOptions(void*, CGImageProvider*, CGRect, CGSize, __CFDictionary const*) ()
#2
0x0000000197035e2c in -[MTKTextureLoaderImageIO decodeCGImageImageProvider:CGImageProvider:options:] ()
#3
0x0000000197035cfc in -[MTKTextureLoaderImageIO decodeCGImage:options:] ()
#4
0x0000000197035b4c in -[MTKTextureLoaderImageIO initWithCGImage:options:error:] ()
#5
0x0000000197032a40 in -[MTKTextureLoader _loadCGImage:options:completionHandler:] ()
#6
0x00000001970313d0 in __68-[MTKTextureLoader newTextureWithCGImage:options:completionHandler:]_block_invoke ()
#7
0x0000000100f65258 in _dispatch_call_block_and_release ()
#8
0x0000000100f65218 in _dispatch_client_callout ()
#9
0x0000000100f71334 in _dispatch_continuation_pop ()
#10
0x0000000100f70fa8 in _dispatch_async_redirect_invoke ()
#11
0x0000000100f74e2c in _dispatch_root_queue_drain ()
#12
0x0000000100f74b78 in _dispatch_worker_thread3 ()
#13
0x000000018482b2a0 in _pthread_wqthread ()
#14
0x000000018482ad8c in start_wqthread ()
Enqueued from NSOperationQueue 0x170222f00 :: NSOperation 0x17024c540 (QOS: DEFAULT) (Thread 18)Queue : NSOperationQueue 0x170222f00 :: NSOperation 0x17024c540 (QOS: DEFAULT) (serial)
#0
0x0000000100f70b30 in _dispatch_queue_push ()
#1
0x0000000197031388 in -[MTKTextureLoader newTextureWithCGImage:options:completionHandler:] ()
#2
0x0000000100082900 in MTKTextureLoader.newTexture(with : UIImage, options : [String : NSObject]?, completionHandler : (MTLTexture?, Error?) -> ()) -> () at /Users/david/projects/InstaVR/instavr-ios-sdk/instavr-ios-sdk/sdk/gfx/prims/Texture.swift:146
Post marked as unsolved
817
Views
I'm trying to render video to a Metal texture.I followed this as the base of my class: https://github.com/FlexMonkey/VideoEffects/blob/master/VideoEffects/FilteredVideoVendor.swiftIt basically opens a video using AVPlayer, and it creates a CIContext to work with the frames.And on initialization, I create a texture like this,let desc = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .rgba8Unorm, width: 256, height: 256, mipmapped: false)
texture = device.makeTexture(descriptor: desc)In every step of the CADisplayLink function I call this, func renderMetalTexture() {
guard let img = unfilteredImage,
let tex = texture else {
return
}
let rect = CGRect(x: 0, y: 0, width: 256, height: 256)
ciContext.render(img, to: tex, commandBuffer: nil, bounds: rect, colorSpace: CGColorSpace.sRGB as! CGColorSpace)
}When I try to execute this code, the application crashes without much explanation.EXC_BREAKPOINT (code=1, subcode=0x1000fb578)Any idea of what's going on? I couldn't find any help code. The only thing I could find are the slides of session 510 from WDC2015 but the only explanation there is that the commandBuffer can be nil...