mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Fix EXC_BAD_ACCESS crash when calling payload delegate methods.
Objective-C objects cannot be captured by reference in C++ lambdas and must always be captured by value. This also takes a copy of the data returned from the Wi-Fi LAN reader, to prevent potential intermittent empty packet issues. Fixes: #1702 PiperOrigin-RevId: 533925980
This commit is contained in:
committed by
Copybara-Service
parent
c9884f6218
commit
3c72e4f40c
@@ -278,13 +278,13 @@ GNCStatus GNCStatusFromCppStatus(Status status) {
|
||||
std::string endpoint_id = [endpointID cStringUsingEncoding:[NSString defaultCStringEncoding]];
|
||||
|
||||
PayloadListener listener;
|
||||
listener.payload_cb = [&delegate](absl::string_view endpoint_id, Payload payload) {
|
||||
listener.payload_cb = [delegate](absl::string_view endpoint_id, Payload payload) {
|
||||
NSString *endpointID = @(std::string(endpoint_id).c_str());
|
||||
GNCPayload *gncPayload = [GNCPayload fromCpp:std::move(payload)];
|
||||
[delegate receivedPayload:gncPayload fromEndpoint:endpointID];
|
||||
};
|
||||
listener.payload_progress_cb =
|
||||
[&delegate](absl::string_view endpoint_id, const PayloadProgressInfo &info) {
|
||||
[delegate](absl::string_view endpoint_id, const PayloadProgressInfo &info) {
|
||||
NSString *endpointID = @(std::string(endpoint_id).c_str());
|
||||
GNCPayloadStatus status;
|
||||
switch (info.status) {
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
}
|
||||
#if __LP64__
|
||||
// This cast is only safe in a 64-bit runtime.
|
||||
blockResult = (NSData *)content;
|
||||
blockResult = [(NSData *)content copy];
|
||||
#else
|
||||
blockResult = nil;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user