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

Null Pointer Crash in KeyboardAutoScrollManager.AdjustPosition #21160

Closed
frankus opened this issue Mar 12, 2024 · 3 comments · Fixed by #21753
Closed

Null Pointer Crash in KeyboardAutoScrollManager.AdjustPosition #21160

frankus opened this issue Mar 12, 2024 · 3 comments · Fixed by #21753
Labels
area-keyboard Keyboard, soft keyboard fixed-in-8.0.40 fixed-in-9.0.0-preview.5.24307.10 legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@frankus
Copy link

frankus commented Mar 12, 2024

Description

When testing a plugin that uses a third-party SDK to present UI, presenting a full-screen modal view controller with text fields results in a crash (null pointer exception) in the AdjustPosition method of KeyboardAutoScrollManager.

Changing the modal presentation style to something other than .FullScreen is a workaround that avoids the crash.

Steps to Reproduce

  1. Create a new Maui App from the template
  2. Replace the contents of MainPage.xaml with the code snippet below
  3. Build and run the app for iOS (dotnet build -f:net8.0-ios -t:Run)
  4. In the app, click the "click me" button, and click into one of the text fields, and then the other text field
  5. Observe a crash with a null pointer exception in KeyboardAutoScrollManager.AdjustPosition
using CoreGraphics;
using UIKit;

namespace keyboard_crash;

public partial class MainPage : ContentPage
{
	public MainPage()
	{
		InitializeComponent();
	}

	private void OnCounterClicked(object sender, EventArgs e)
	{
		var rootVC = UIApplication.SharedApplication.KeyWindow.RootViewController;

		if (rootVC != null) {
			var testVC = new TestViewController();

			var testNC = new UINavigationController(testVC);

			// Changing this from the default to "FullScreen" is the key to making it crash.
			testNC.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;

			rootVC.PresentViewController(testNC, true, null);
		}
	}
}

public class TestViewController: UIViewController {
	UITextField TextField1;
	UITextField TextField2;

	public override void ViewDidLoad() {
		base.ViewDidLoad();

		View.BackgroundColor = UIColor.White;

		TextField1 = new UITextField(new CGRect(20, 120, 200, 20));
		TextField2 = new UITextField(new CGRect(20, 220, 200, 20));

		TextField1.BorderStyle = UITextBorderStyle.RoundedRect;
		TextField2.BorderStyle = UITextBorderStyle.RoundedRect;

		View.AddSubview(TextField1);
		View.AddSubview(TextField2);
	}
}

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

Only tested with iOS 17.0

Did you find any workaround?

Yes, presenting the view controller with a ModalPresentationStyle of e.g. PageSheet avoids the crash.

Relevant log output

No response

@frankus frankus added the t/bug Something isn't working label Mar 12, 2024
@bradencohen
Copy link
Contributor

bradencohen commented Mar 12, 2024

I ran into some trouble with this too. My workaround was to call:

#if IOS
            KeyboardAutoManagerScroll.Disconnect();
#endif

You can re-connect it if desired.

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Mar 13, 2024
@Zhanglirong-Winnie
Copy link

Verified this issue with Visual Studio 17.10.0 Preview 2. Can repro on iOS platform with above code.

@Eilon Eilon added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Mar 29, 2024
@tj-devel709
Copy link
Member

Thank you for this issue. This is the same problem as #21726 which has a PR here: #21753!

@Eilon Eilon added the area-keyboard Keyboard, soft keyboard label May 13, 2024
@samhouts samhouts added this to the .NET 8 SR5 milestone May 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-keyboard Keyboard, soft keyboard fixed-in-8.0.40 fixed-in-9.0.0-preview.5.24307.10 legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants