ryanmcgrath / cacao

Rust bindings for AppKit (macOS) and UIKit (iOS/tvOS). Experimental, but working!
MIT License
1.79k stars 65 forks source link

_action.request.absolute_url() exit with segmentation fault error #115

Closed cezaraag closed 7 months ago

cezaraag commented 7 months ago

I'm experiencing a segmentation fault error when calling _action.request.absolute_url() in policy_for_navigation_action of the web view delegate. Do you have any suggestions for fixing this?

fn policy_for_navigation_action<F: Fn(cacao::webview::NavigationPolicy)>(&self, _action: cacao::webview::NavigationAction, handler: F) {
        let url = _action.request.absolute_url().to_ascii_lowercase();
        handler(cacao::webview::NavigationPolicy::Allow);
    }
ryanmcgrath commented 7 months ago

Mmm, need more info before we can even begin to debug this.

What version of macOS? What version of cacao - published release on crates.io or trunk?

cezaraag commented 7 months ago

thank you for the quick response. Few more details: Apple M2 Pro macOS: 14.1.1 (23B81)

I tried in two cacao releases: v0.3.2 and I'm currently testing on v0.4.0-beta2. Both had the same issue.

I started trying to println the value. When I tried it, it print the url value but also exit with segmentation fault.

ryanmcgrath commented 7 months ago

Sounds like shenanigans with retain/release in the ObjC layer. Can you share a quick test case by any chance?

cezaraag commented 7 months ago

Sorry, I didn't understand your question. Would you like me to provide a test case for you to reproduce the error or would you like me to run a specific test on my machine?

cezaraag commented 7 months ago

If the goal is to reproduce the error, in my environment the error happens in any call of URLRequest.absolute_url from the NavigationAction. I'm doing the call on the policy_for_navigation_action of WebViewDelegate implementation.

ryanmcgrath commented 7 months ago

Yeah, it's most likely that the NSURLRequest that the Action has needs to be retained.

You could tweak src/webview/action.rs absolute_url to call retain rather than from_retained, would likely fix it. If it does, feel free to PR it.

cezaraag commented 7 months ago

I am happy to submit the pull request, but it appears to have already been fixed in the trunk. I will test the trunk version and inform you of the results. Thank you for your assistance.

cezaraag commented 7 months ago

Your suggestion fixed the issue. :) Thank you! I did a change locally to the v0.4.0-beta2 tag since web view seems to have other issues in trunk. But the fix is applied to trunk already. Let me know if there is a specific branch that you would like to have the PR.