-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panic with error parameter should be set if the method returns NO
when trying to serialize MTLBinaryArchive
#653
Comments
Huh, that's very odd, and contrary to the documented behaviour of the function - the header says:
Emphasis mine, I cannot read this in any other way than that the error is set if the method fails (and that's also the expected behaviour in general, see #276 for more details). So I'd argue that this is an Apple bug, but I guess I'll have a look at what Swift does in this case.
Yeah, see also #539, should hopefully be a bit better with the next version of |
Smaller reproducer: use objc2::rc::Retained;
use objc2_foundation::{ns_string, NSURL};
use objc2_metal::{
MTLBinaryArchive, MTLBinaryArchiveDescriptor, MTLCreateSystemDefaultDevice, MTLDevice,
};
#[link(name = "CoreGraphics", kind = "framework")]
extern "C" {}
fn main() {
unsafe {
let device = Retained::from_raw(MTLCreateSystemDefaultDevice()).unwrap();
let binary_archive = device
.newBinaryArchiveWithDescriptor_error(&MTLBinaryArchiveDescriptor::new())
.unwrap();
let metal_lib = NSURL::URLWithString(ns_string!("file://test.metallib")).unwrap();
if let Err(e) = binary_archive.serializeToURL_error(&metal_lib) {
eprintln!("{:?}", e.localizedDescription());
}
}
} |
Equivalent Swift: import Foundation
import Metal
import CoreGraphics
let device = MTLCreateSystemDefaultDevice()!
let binary_archive = try! device.makeBinaryArchive(descriptor: MTLBinaryArchiveDescriptor())
let metal_lib = NSURL(string: "file://test.metallib")!
do {
try binary_archive.serialize(to: metal_lib as URL)
} catch {
print(error)
} Seems like they return a |
In newer versions |
Hmm, wondering how we can do the same, without defining a whole new Although all of that's still fallible in OOM situations, so we'll still have to panic/abort somewhere. |
And the error should of course be cached. |
I'm trying to serialize a
MTLBinaryArchive
to a file inside the application bundle caches directory.This is panicking unexpectedly with objc2 generated code
How I'm debugging this is a little complex so it might just be easier to give repro instructions.
This won't actually give you the full unwind message though due to C-unwind ABI changes, but I wrapped it in
catch_unwind
in the repro branch (https://github.com/SnowflakePowered/librashader/tree/metal-shader-cache) to get more of that out. I got this backtrace via a very finicky debug setup with C ABI bindings and running within XCode so it's too complicated to set up compared to just thecargo test
.The text was updated successfully, but these errors were encountered: