Skip to content
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

Use closure syntax for weak and unowned vars. #160

Merged
merged 1 commit into from
Apr 14, 2016
Merged

Use closure syntax for weak and unowned vars. #160

merged 1 commit into from
Apr 14, 2016

Conversation

oNaiPs
Copy link
Contributor

@oNaiPs oNaiPs commented Apr 14, 2016

This PR uses closure syntax to define the weak/unowned variables or self, and fixes strong reference loop bugs in setLocalDescription and setRemoteDescription.
Without this fix, calling RTCPeerConnection.close() on javascript will not correctly deallocate all underlying native objects.

@oNaiPs oNaiPs closed this Apr 14, 2016
@oNaiPs oNaiPs reopened this Apr 14, 2016
@ibc
Copy link
Collaborator

ibc commented Apr 14, 2016

Awesome. Swift is hateful! (unowned self...).

Thanks a lot. Merged.

@ibc ibc merged commit ac4e857 into cordova-rtc:master Apr 14, 2016
@ibc
Copy link
Collaborator

ibc commented Apr 14, 2016

I've applied this PR and got this crash:

captura de pantalla 2016-04-14 a las 12 34 44

@ibc
Copy link
Collaborator

ibc commented Apr 14, 2016

It does not crash as follows:

func RTCPeerConnection_close(command: CDVInvokedUrlCommand) {
        NSLog("iosrtcPlugin#RTCPeerConnection_close()")

        let pcId = command.argumentAtIndex(0) as! Int
        let pluginRTCPeerConnection = self.pluginRTCPeerConnections[pcId]

        if pluginRTCPeerConnection == nil {
            NSLog("iosrtcPlugin#RTCPeerConnection_close() | ERROR: pluginRTCPeerConnection with pcId=%@ does not exist", String(pcId))
            return;
        }

        dispatch_async(self.queue) {
            pluginRTCPeerConnection!.close()
        }

        // Remove the pluginRTCPeerConnection from the dictionary.
        self.pluginRTCPeerConnections[pcId] = nil
    }

I've also tried passing [weak pluginRTCPeerConnection] in to dispatch_async() but it crashes as well, so I'm worried whether the native object is not properly deallocated.

If so, would this work?

        dispatch_async(self.queue) {
            pluginRTCPeerConnection!.close()
            pluginRTCPeerConnection = nil
        }

@ibc
Copy link
Collaborator

ibc commented Apr 14, 2016

I've open an issue for this at #161, let's please comment about this there.

@saghul
Copy link
Collaborator

saghul commented Apr 14, 2016

I've also got the crash. Can you please revert it until it's properly
tested?
On Apr 14, 2016 07:52, "Iñaki Baz Castillo" [email protected]
wrote:

I've open an issue for this at #161
#161, let's
please comment about this there.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#160 (comment)

@ibc
Copy link
Collaborator

ibc commented Apr 14, 2016

Please guys... let's go to #161, there are updates there, including a commit preventing the crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants