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

Crash in android #374

Closed
Coloryr opened this issue Oct 1, 2023 · 1 comment
Closed

Crash in android #374

Coloryr opened this issue Oct 1, 2023 · 1 comment

Comments

@Coloryr
Copy link

Coloryr commented Oct 1, 2023

android.runtime.JavaProxyThrowable: System.ArgumentOutOfRangeException: Value must be between 1 and 105 Arg_ParamName_Name, number
ArgumentOutOfRange_ActualValue, 0
   at AvaloniaEdit.Document.TextDocument.GetLineByNumber(Int32 number)
   at AvaloniaEdit.Document.TextDocument.GetOffset(Int32 line, Int32 column)
   at AvaloniaEdit.Document.TextDocument.GetOffset(TextLocation location)
   at AvaloniaEdit.Editing.Selection.Create(TextArea textArea, TextViewPosition start, TextViewPosition end)
   at AvaloniaEdit.Editing.EmptySelection.StartSelectionOrSetEndpoint(TextViewPosition startPosition, TextViewPosition endPosition)
   at AvaloniaEdit.Editing.TextArea.TextAreaTextInputMethodClient.set_Selection(TextSelection value)
   at Avalonia.Android.AndroidInputMethod`1[[Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl.ViewImpl, Avalonia.Android, Version=11.0.4.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].OnSurroundingTextChanged()
   at Avalonia.Android.AndroidInputMethod`1[[Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl.ViewImpl, Avalonia.Android, Version=11.0.4.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]]._client_SurroundingTextChanged(Object , EventArgs )
   at Avalonia.Input.TextInput.TextInputMethodClient.RaiseSurroundingTextChanged()
   at AvaloniaEdit.Editing.TextArea.TextAreaTextInputMethodClient.Caret_PositionChanged(Object sender, EventArgs e)
   at AvaloniaEdit.Editing.Caret.RaisePositionChanged()
   at AvaloniaEdit.Editing.Caret.set_Position(TextViewPosition value)
   at AvaloniaEdit.Editing.SelectionMouseHandler.SetCaretOffsetToMousePosition(PointerEventArgs e, ISegment allowedSegment)
   at AvaloniaEdit.Editing.SelectionMouseHandler.TextArea_MouseLeftButtonDown(Object sender, PointerPressedEventArgs e)
   at Avalonia.Interactivity.Interactive.<AddHandler>g__InvokeAdapter|4_0[PointerPressedEventArgs](Delegate , Object , RoutedEventArgs )
   at Avalonia.Interactivity.Interactive.<>c__4`1[[Avalonia.Input.PointerPressedEventArgs, Avalonia.Base, Version=11.0.999.0, Culture=neutral, PublicKeyToken=c8d484a7012f9a8b]].<AddHandler>b__4_1(Delegate , Object , RoutedEventArgs )
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs )
   at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive , RoutedEventArgs )
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs )
   at Avalonia.Input.TouchDevice.ProcessRawEvent(RawInputEventArgs )
   at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs )
   at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs )
   at Avalonia.Android.Platform.Specific.Helpers.AndroidMotionEventsHelper.DispatchMotionEvent(MotionEvent , Boolean& )
   at Avalonia.Android.Platform.SkiaPlatform.TopLevelImpl.ViewImpl.DispatchTouchEvent(MotionEvent )
   at Android.Views.View.n_DispatchTouchEvent_Landroid_view_MotionEvent_(IntPtr , IntPtr , IntPtr )
   at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPL_Z(_JniMarshal_PPL_Z , IntPtr , IntPtr , IntPtr )
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.n_dispatchTouchEvent(Native Method)
	at crc64bd239b21961e24ab.TopLevelImpl_ViewImpl.dispatchTouchEvent(TopLevelImpl_ViewImpl.java:73)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3249)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2881)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3249)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2881)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3249)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2881)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3249)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2881)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3249)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2881)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3249)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2881)
	at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:765)
	at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:2013)
	at android.app.Activity.dispatchTouchEvent(Activity.java:4180)
	at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:70)
	at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:697)
	at android.view.View.dispatchPointerEvent(View.java:13967)
	at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:6489)
	at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:6284)
	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5673)
	at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5726)
	at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5692)
	at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:5850)
	at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5700)
	at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:5907)
	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5673)
	at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:5726)
	at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:5692)
	at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:5700)
	at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:5673)
	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:8857)
	at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:8777)
	at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:8730)
	at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:9117)
	at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:239)
	at android.os.MessageQueue.nativePollOnce(Native Method)
	at android.os.MessageQueue.next(MessageQueue.java:363)
	at android.os.Looper.loop(Looper.java:176)
	at android.app.ActivityThread.main(ActivityThread.java:8673)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1109)

@pazof
Copy link
Contributor

pazof commented Dec 22, 2023

I got it fixed by improving the setter for the TextEdit.Selection :

index 4414f39..7b8b4dd 100644
--- a/src/AvaloniaEdit/Editing/TextArea.cs
+++ b/src/AvaloniaEdit/Editing/TextArea.cs
@@ -20,6 +20,7 @@ using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Controls.Presenters;
 using Avalonia.Controls.Primitives;
+using Avalonia.Dialogs.Internal;
 using Avalonia.Input;
 using Avalonia.Input.TextInput;
 using Avalonia.Interactivity;
@@ -1200,8 +1201,9 @@ namespace AvaloniaEdit.Editing
                 }
                 set
                 {
-                    var selection = _textArea.Selection;
-
+                    if (_textArea == null) return;
+                    var selection =  _textArea.Selection;
+                    if (selection.StartPosition.Line == 0) return;
                     _textArea.Selection = selection.StartSelectionOrSetEndpoint(
                         new TextViewPosition(selection.StartPosition.Line, value.Start),
                         new TextViewPosition(selection.StartPosition.Line, value.End));

@danipen danipen closed this as completed in 57a2cd8 Jan 8, 2024
danipen added a commit that referenced this issue Jan 8, 2024
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

No branches or pull requests

2 participants