Borni 1 Posted September 18, 2024 HI Folks, with the return key in a tmemo it crahses with the message java.lang.indexoutofboundsexception under Android32/64. Someone must have noticed this before !!! BR Borni Share this post Link to post
hsauro 43 Posted September 18, 2024 (edited) What framework, VCL or FMX? Edited September 18, 2024 by hsauro Share this post Link to post
Uwe Raabe 2152 Posted September 18, 2024 28 minutes ago, hsauro said: What framework, VCL or FMX? Really? 47 minutes ago, Borni said: under Android32/64. 5 Share this post Link to post
JonRobertson 83 Posted September 18, 2024 2 hours ago, Uwe Raabe said: 2 hours ago, Borni said: under Android32/64. And in the topic 1 Share this post Link to post
alejandro.sawers 17 Posted September 18, 2024 3 hours ago, Borni said: with the return key in a tmemo it crahses with the message java.lang.indexoutofboundsexception under Android32/64. A quick test on a Delphi 12.2 blank FMX app with only a TMemo, compiled for Android 64, running on an Android 13 device doesn't show such error. Maybe test with a blank project to discard issues with your Delphi/Android SDK installation. 1 Share this post Link to post
hsauro 43 Posted September 19, 2024 10 hours ago, Uwe Raabe said: Really? Oops sorry. Teach me a lesson for posting. 1 Share this post Link to post
Borni 1 Posted September 19, 2024 (edited) 11 hours ago, alejandro.sawers said: A quick test on a Delphi 12.2 blank FMX app with only a TMemo, compiled for Android 64, running on an Android 13 device doesn't show such error. Maybe test with a blank project to discard issues with your Delphi/Android SDK installation. Nokia 5.4 with Android 12 - > ok Google Pixel 8 Android 14 -> ok Samsung S23 Android 14 -> Exception Galaxy s10+ Android 12 -> Exception Galaxy s24+ Android 14 -> Exception Galaxy Tab A Android 7.1.1 -> Exception all samsung devices ! Edited September 19, 2024 by Borni Share this post Link to post
havrlisan 38 Posted September 19, 2024 Exception occurs on my A52s as well. To reproduce, write a character and press the Return key. Pressing the Return key on an empty line doesn't trigger the exception. Share this post Link to post
Chris Pim 35 Posted September 19, 2024 (edited) Looks very serious. Can you please log it with Embarcadero in their quality portal so they can start investigating? We might get a quick patch from them with any luck. https://embt.atlassian.net/servicedesk/customer/portals Edited September 19, 2024 by Chris Pim Share this post Link to post
havrlisan 38 Posted September 19, 2024 (edited) Upon closer inspection, it has nothing to do with the Return key, but with the caret position. The bug can be reproduced just by tapping on another line, the only condition is that the current line must have at least one character. Stack trace: System._DbgExcNotify(int, void*, System.SmallString<(unsigned char)255>*, void*, void*) System.NotifyReRaise(System.TObject*, void*)($b40000deac336980,$0000006ef3035c10) System._InternalRaiseAtExcept(System.TObject*, void*, bool)($b40000deac336980,$0000006ef3035c10,false) System._RaiseExcept(System.TObject*)($b40000deac336980) System.Internal.Excutils.DoRaiseJNIExceptionCallBack(System.UnicodeString, System.UnicodeString)(??,??) Androidapi.Jni.HandleJNIException(JNINativeInterface**)($b40000701924bbf0) Androidapi.Jnimarshal.ExecJNI(void*, void*, void*, Androidapi.Jnimarshal.JNIMethodInvokeData*, Androidapi.Jnimarshal.m128*)($0000007fe4a32218,$0000007fe4a321f8,$0000007fe4a322f0,$0000007fe4a32200,$0000007fe4a32210) _DispatchToImport Fmx.Platform.Ui.Android.TTextServiceAndroid.InternalUpdateSelection()($b4000070c92faf10) Fmx.Platform.Ui.Android.TTextServiceAndroid.SetText(System.UnicodeString)($b4000070c92faf10,??) Fmx.Text.Texteditor.TTextEditor.UpdateTextInTextService()($b4000070192bc510) Fmx.Text.Texteditor.TTextEditor.SetCaretPosition(Fmx.Text.TCaretPosition const&)($b4000070192bc510,{Line = 1, Pos = 0}) Fmx.Memo.Style.New.TStyledMemo.MMSetCaretPosition(Fmx.Presentation.Messages.TDispatchMessageWithValue__1<Fmx.Text.TCaretPosition>&)($b4000070e92689d0,{MsgID = 5917, Value = {Line = 1, Pos = 0}}) System.TObject.Dispatch(void*)($b40000dfdc2671e0,$0000007fe4a326d8) void Fmx.Presentation.Messages.TMessageSender.SendMessage<Fmx.Text.TCaretPosition>(unsigned short, Fmx.Text.TCaretPosition)($b4000070192bf450,5917,{Line = 1, Pos = 0}) Fmx.Memo.TCustomMemoModel.SetCaretPosition(Fmx.Text.TCaretPosition const&)($b4000070192bf450,{Line = 1, Pos = 0}) Fmx.Memo.TCustomMemoModel.InsertAfter(Fmx.Text.TCaretPosition const&, System.UnicodeString, System.Set<Fmx.Text.TInsertOption, (Fmx.Text.TInsertOption)0, (Fmx.Text.TInsertOption)4>)(??,{Line = 0, Pos = 1},??,{__data = "\\U00000006", __basetype = ??}) Fmx.Memo.Style.New.TStyledMemo.KeyDown(unsigned short&, char16_t&, System.Set<System.Classes.TShiftStateItem, (System.Classes.TShiftStateItem)0, (System.Classes.TShiftStateItem)10>)(??,$0000007fe4a32fa2,U+2fa4 U+e4a3 U+007f U+0000 u'\\xe2\\xbe\\xa4',{__data = "", __basetype = ??}) Fmx.Presentation.Style.TStyledPresentation.PMKeyDown(Fmx.Presentation.Messages.TDispatchMessageWithValue__1<Fmx.Controls.Presentation.TKeyInfo>&)($b4000070e92689d0,{MsgID = 1056, Value = {Key = 13, KeyChar = U+0000 u'\\\\0', Shift = {__data = "", __basetype = ??}}}) System.TObject.Dispatch(void*)($b40000dfdc2671e0,$0000007fe4a32fa0) void Fmx.Presentation.Messages.TMessageSender.SendMessageWithResult<Fmx.Controls.Presentation.TKeyInfo>(unsigned short, Fmx.Controls.Presentation.TKeyInfo&)($b400006fb92f9d80,1056,{Key = 13, KeyChar = U+0000 u'\\\\0', Shift = {__data = "", __basetype = ??}}) Fmx.Controls.Presentation.TPresentedControl.KeyDown(unsigned short&, char16_t&, System.Set<System.Classes.TShiftStateItem, (System.Classes.TShiftStateItem)0, (System.Classes.TShiftStateItem)10>)($b400006f99280520,$0000007fe4a3330a,U+3302 U+e4a3 U+007f U+0000 u'\\xe3\\x8c\\x82',{__data = "", __basetype = ??}) Fmx.Forms.TCommonCustomForm.KeyDown(unsigned short&, char16_t&, System.Set<System.Classes.TShiftStateItem, (System.Classes.TShiftStateItem)0, (System.Classes.TShiftStateItem)10>)($b400006f9927be50,$0000007fe4a3330a,U+3302 U+e4a3 U+007f U+0000 u'\\xe3\\x8c\\x82',{__data = "", __basetype = ??}) Fmx.Platform.Ui.Android.TAndroidTextInputManager.KeyDown(unsigned short&, char16_t&, System.Set<System.Classes.TShiftStateItem, (System.Classes.TShiftStateItem)0, (System.Classes.TShiftStateItem)10>)($b400007009347710,$0000007fe4a3330a,U+3302 U+e4a3 U+007f U+0000 u'\\xe3\\x8c\\x82',{__data = "", __basetype = ??}) Fmx.Platform.Ui.Android.TAndroidTextInputManager.HandleAndroidKeyEvent(AInputEvent*)($b400007009347710,$b40000700939d2a0) Fmx.Platform.Android.TPlatformAndroid.HandleAndroidInputEvent(Androidapi.Appglue.TAndroidApplicationGlue*, AInputEvent*)($b4000070192be490,$b40000700939d2a0) Androidapi.Appglue.TAndroidApplicationGlue.InputEventHandler(int, int, void*) :0000007234A78B74 android::Looper::pollInner(int) :0000007234A7862C android::Looper::pollOnce(int, int*, int*, void**) :00000072278C689C ___lldb_unnamed_symbol9344 :000000009D7B6340 ?? The TTextEditor.FCaretPosition was updated while TTextService.FCaretPosition wasn't, and the TTextEditor.UpdateTextInTextService gets called before the TTextService receives the position update. The UpdateTextInTextService passes the string of the newly selected line to the TTextService.SetText, which, among other code, does this: FTextView.setText(StrToJCharSequence(FText), TJTextView_BufferType.JavaClass.EDITABLE); // In some cases, EditText can reset selection/caret position to 0. So if user removes text via vkBackspace, // the backspace button in Soft Keyboard can be unpressed automatically. InternalUpdateSelection; Judging from the comment, that second line seems like a new addition. Tracing into it, lo and behold: procedure TTextServiceAndroid.InternalUpdateSelection; var SelStart, SelEnd: Integer; begin if FTextView = nil then Exit; CalculateSelectionBounds(SelStart, SelEnd); if SelEnd - SelStart > 0 then FTextView.setSelection(SelStart, SelEnd) else FTextView.setSelection(CaretPosition.X); // this one gets executed end; It uses its non-updated caret position to update the selection. Edited September 19, 2024 by havrlisan typo 1 Share this post Link to post
havrlisan 38 Posted September 19, 2024 Reported on QP: https://embt.atlassian.net/servicedesk/customer/portal/1/RSS-1840 1 Share this post Link to post
Borni 1 Posted September 19, 2024 43 minutes ago, havrlisan said: Reported on QP: https://embt.atlassian.net/servicedesk/customer/portal/1/RSS-1840 in FMX.Platform.UI.Android.pas markieren Code: procedure TTextServiceAndroid.InternalUpdateSelection; var SelStart, SelEnd: Integer; begin if FTextView = nil then Exit; CalculateSelectionBounds(SelStart, SelEnd); if SelEnd - SelStart > 0 then FTextView.setSelection(SelStart, SelEnd) else FTextView.setSelection(JCharSequenceToStr(FTextView.getText).length); // the chagnes found by Enri end; 1 Share this post Link to post
alejandro.sawers 17 Posted September 19, 2024 Put my hands on a Samsung A12 and can confirm the issue when pressing the return key: Testing on a Redmi Note 11 doesn't cause the exception, but by @havrlisan's comment it does happen when tapping on the memo to move the caret from a non-empty line to an empty one. 3 hours ago, Borni said: in FMX.Platform.UI.Android.pas markieren Code: procedure TTextServiceAndroid.InternalUpdateSelection; var SelStart, SelEnd: Integer; begin if FTextView = nil then Exit; CalculateSelectionBounds(SelStart, SelEnd); if SelEnd - SelStart > 0 then FTextView.setSelection(SelStart, SelEnd) else FTextView.setSelection(JCharSequenceToStr(FTextView.getText).length); // the chagnes found by Enri end; This change seems to solve the issue on both Samsung and non-Samsung devices. 2 Share this post Link to post
Ian Barker 20 Posted September 19, 2024 Thanks for letting us know about this. I have raised it with the PM team to look at and validate ASAP. FWIW my own personal mobile is a Samsung device. 1 Share this post Link to post
alejandro.sawers 17 Posted October 8, 2024 Just as a follow-up the workaround posted by @Borni has the side-effect of sending the caret to the end of the line when deleting a character using the soft keyboard, so I ended up changing this: On 9/19/2024 at 4:47 AM, Borni said: FTextView.setSelection(JCharSequenceToStr(FTextView.getText).length); // the chagnes found by Enri To this: FTextView.setSelection(SelStart); Additionally there is another exception thrown when moving the caret with selected text to a line with less characters than the current selection (this happens on Samsung and non-Samsung devices alike). To mitigate that I had to add a couple of lines just before the if SelEnd - SelStart > 0 then check (line 1953) in the same procedure: // Normalize selection indexes SelStart:=Min(SelStart, JCharSequenceToStr(FTextView.getText).length); SelEnd:=Min(SelEnd, JCharSequenceToStr(FTextView.getText).length); Share this post Link to post
Marlon Nardi 0 Posted October 16, 2024 In practice procedure TTextServiceAndroid.InternalUpdateSelection; var SelStart, SelEnd: Integer; begin if FTextView = nil then Exit; CalculateSelectionBounds(SelStart, SelEnd); SelStart := Min(SelStart, JCharSequenceToStr(FTextView.getText).length); SelEnd := Min(SelEnd, JCharSequenceToStr(FTextView.getText).length); if SelEnd - SelStart > 0 then FTextView.setSelection(SelStart, SelEnd) else FTextView.setSelection(SelStart); end; worked in all tests Share this post Link to post
JohnLM 27 Posted October 17, 2024 (edited) I use the TMemo in Android apps a lot, but due to this issue (I suffer from this as well--Galaxy S10+ phone) I've been holding off compiling to Android via 12.2 Does the Inline Patch 1 from 10-17-2024 fix this issue ? As soon as I can, I will be making an HDD image before I proceed to this Inline Patch 1 process. Edited October 17, 2024 by JohnLM Share this post Link to post
havrlisan 38 Posted October 18, 2024 7 hours ago, JohnLM said: I use the TMemo in Android apps a lot, but due to this issue (I suffer from this as well--Galaxy S10+ phone) I've been holding off compiling to Android via 12.2 Does the Inline Patch 1 from 10-17-2024 fix this issue ? As soon as I can, I will be making an HDD image before I proceed to this Inline Patch 1 process. It does. You can read the change log here: https://blogs.embarcadero.com/rad-studio-12-2-athens-inline-patch-1-available/ Share this post Link to post
andremurta 0 Posted November 20, 2024 Guys, how exactly did you manage to solve this problem by installing patch 1 released on 2024-10-17? I use RAD Studio Enterprise 12.2 Patch 1 (compilation 29.0.53571.9782) and this problem persists. I have my application installed on some Samsung models (Note 9, Note 10, S23, S24 Ultra) and on all these devices the TMemo component causes the exception described in the initial post. I registered the problem with Embarcadero support and the response was to inform me that there is already a record of this problem, but no mention of possible solutions. Share this post Link to post
DelphiUdIT 243 Posted November 20, 2024 3 hours ago, andremurta said: I use RAD Studio Enterprise 12.2 Patch 1 (compilation 29.0.53571.9782) Something wrong with your update, the build should be "29.0.53982.0329" ... 1 1 Share this post Link to post
Saphire Neil 1 Posted February 6 (edited) Hello All, Just to add for completeness: To fix your code copy the files "FMX.Platform.UI.Android" & "FMX.Presentation.Android.Style" into your project folder. Open "FMX.Platform.UI.Android" and search for "procedure TTextServiceAndroid.InternalUpdateSelection;" Replace this procedure with the following: procedure TTextServiceAndroid.InternalUpdateSelection; var SelStart, SelEnd: Integer; begin if FTextView = nil then Exit; CalculateSelectionBounds(SelStart, SelEnd); // Fixes issue with enter key in TMemo - https://en.delphipraxis.net/topic/12197-delphi-122-tmemo-indexoutofbounds/?tab=comments#comment-95629 // This is the orginal code // if SelEnd - SelStart > 0 then // FTextView.setSelection(SelStart, SelEnd) // else // FTextView.setSelection(CaretPosition.X); if SelEnd - SelStart > 0 then FTextView.setSelection(SelStart, SelEnd) else if CaretPosition.X > JCharSequenceToStr(FTextView.getText).Length then FTextView.setSelection(JCharSequenceToStr(FTextView.getText).Length) else FTextView.setSelection(CaretPosition.X); end; The underlying issue is that when you press the enter key at the end of the line on a TMEMO "CaretPosition.X" is returning 1 character more than the length of the actual string in the memo. The fix just checks if "CaretPosition.X" is longer than the length and if it is it move the caret to the "Length". Edited February 6 by Saphire Neil Share this post Link to post
fisipjm 0 Posted Tuesday at 02:48 PM Hi everyone, While searching for a solution to a similar problem, I came across this thread. Although it's not exactly the same issue, I believe it's worth adding this here for others who might be facing similar crashes. I recently encountered a bug where moving the caret (text cursor) while a shadow effect is active on a FireMonkey form (using Skia/Vulkan on Android) causes the app to crash. This happens during caret movement (by dragging it so the magnifyer cricle appears). More technical details and a demo are available in the official Embarcadero Quality Portal under RSS-3637. Steps to reproduce: put any Component on the Form (label, rectangle, edit, not matter what) apply a shadow effect Enable Skia put Tedit or Memo on the Form Run under Android, write some Text and try to move the caret by dragging it Tested and confirmed on: Pixel 7a Pixel 9a Samsung Galaxy S22 Just wanted to document it here in case anyone else is debugging the same symptoms. Hope this helps someone avoid hours of head-scratching. Share this post Link to post
alejandro.sawers 17 Posted 10 hours ago Thanks for reporting. I think the correct URL to the QP issue should be this one. That being said, I tested compiling the test project on Delphi 12.2, running on a Samsung A15, and on dragging the green caret the app doesn't crash, but it is really glitchy: - It freezes a couple seconds before the magnifier spawns, only to hang another couple seconds until it goes away (still running after that, and Monitor reports things like "Skipped 169 frames! The application may be doing too much work on its main thread."). - After some minutes running the app starts to paint itself incorrectly (see attachment). - After sending the app to the background and restoring it its all black, but I can still interact with the TEdit apparently. At this point Monitor shows tons of "ERROR: Format allocation info not found for format: 38" and similar messages. Looks like a combination of features that went untested and is very unstable. I would stay away from this combo until fixed. video5066602786846672458.mp4 Share this post Link to post