I want to bind a smartpointer to xpc connection, will below work?
I have class A like this:
class A {
};
Initialization with xpc_connection currentConnection
auto aObj = std::make_shared<A>();
xpc_connection_set_context(currentConnection, aObj.get())
After I done with the connection, I get back the raw pointer:
auto pObj = reinterpret_cast<A*>(xpc_connection_get_context(currentConnection));
if (pObj != nullptr)
{
std::shared_ptr<A> asmarter(pObj);
asmarter.reset(); //release the smart pointer
}
Will this work?
I posted the screenshot since it contains the error information which might help understanding the problem.
In such situations it’s better to include a crash report. See Posting a Crash Report for details on post to post that.
that
surfaceObj
was from callback block ofCGDisplayStreamCreateWithDispatchQueue
, and its value is not null but not sure if it is valid.
If it’s not NULL
then it’s definitely valid at the point that you got it. Keep in mind that it’s only valid until you return from the block that you pass to CGDisplayStreamCreateWithDispatchQueue
. If you call IOSurfaceCreateXPCObject
inside that block, it should be fine. If not, you’ll need to retain it until you make that call.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"