I'm working on an editor for Bevy games and wanted the following workflow:
Launch the game process
Host a Metal view for the game's render target
Use an XPC service to transfer an MTLSharedTextureHandle
Keep the connection for editor/game communication and hot reload
As such I created the following editor service:
public let XPCEditorServiceName = "org.bevy.editor"
public enum XPCEditorMessage: Codable {
case ping
}
public enum XPCEditorReply: Codable {
case pong
}
extension XPCListener {
static let bevy = try! XPCListener(service: XPCEditorServiceName) { request in
request.accept(XPCEditorService.init)
}
}
struct XPCEditorService: XPCPeerHandler {
let session: XPCSession
private func handle(_ message: XPCEditorMessage) -> XPCEditorReply? {
switch message {
case .ping:
return .pong
}
}
func handleIncomingRequest(_ message: XPCReceivedMessage) -> (any Encodable)? {
do {
return handle(try message.decode())
} catch {
return nil
}
}
func handleCancellation(error: XPCRichError) {
print(error)
}
}
and I initialize it in my app's App initializer:
// Launch the XPC service
print(XPCListener.bevy)
I wanted to test this using an executable target with the following main.swift:
let session = try XPCSession(xpcService: XPCEditorServiceName)
let response: XPCEditorReply = try session.sendSync(XPCEditorMessage.ping)
print("Connected to editor!")
The editor prints Listener<org.bevy.editor>(Active) but the game fails with Underlying connection was invalidated. Reason: Connection init failed at lookup with error 3 - No such process
What am I doing wrong?
PS. Would also appreciate an example of sending & rendering the MTLSharedTextureHandle both in editor & game.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
Opened feedback item FB21877364.
Context
I have the following Metal shader, which replaces one color with another.
[[ stitchable ]]
half4 recolor(
float2 position,
half4 currentColor,
half4 from,
half4 to
) {
if (all(currentColor == from))
return to;
return currentColor;
}
Given this SwiftUI view:
let shader = ShaderLibrary.recolor(.color(.red), .color(.green))
Color.red
.colorEffect(shader)
I get a red rectangle instead of the expected green one.
Note that this works on both dynamic and non-dynamic colors.
Note that this sometimes works with some colors, which is very inconvenient when trying to figure out what's going on.
Did I miss something? I would've expected the shader to work with colors the same way.
Issue
To really highlight the issue, here's another test case.
I'll define #94877E in an Asset Catalog as example and check the RGB values using the Digital Color Meter app in "Display native values" mode.
We'll use the following shader to determine how colorEffect receives colors:
[[ stitchable ]]
half4 test(
float2 position,
half4 currentColor,
half4 color
) {
return color;
}
The following view yields "R: 0.572, G: 0.531, B: 0.498".
Color.example
While this one yields "R: 0.572, G: 0.531, B: 0.499".
let shader = ShaderLibrary.test(.color(Color.example))
Color.white.colorEffect(shader)
I would expect them to match.
Topic:
UI Frameworks
SubTopic:
SwiftUI