-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Random crashes in GenericStyleArea.visibleParToAllParIndex #777
Comments
Apparently resizing the window (sometimes?) fixes it. |
I write some blank paragraphs (only an ENTER each row).
I checked source code of Paragraph<PS, SEG, S> visibleP = getVisibleParagraphs().get(visibleParIndex);
for (int index = 0; index < getParagraphs().size(); index++) {
if (getParagraph(index) == visibleP) {
return index;
}
} It is a simple comparison between results of Unfortunately, those two methods will give different results corresponding to the same blank paragraphs. I use such a test case with 4 rows:
, only the first and fourth row can be matched. |
@lhttjdr Thank you for the update to this issue. Could you please provide code for a simple test case that throws out "Unreachable code" error. |
@Jugen Thank you for your great job at first. |
Ok, so after some research I've found that this happens because there is a discrepancy (based on ==) between the Paragraph objects returned by getParagraphs() and getVisibleParagraphs() in that the former contains the paragraphs submitted in an edit but the latter contains paragraphs merged between what was there before and whatever is there now. So when a lookup is performed trying to find the exact object from the visible paragraph list in the list returned by getParagraphs, no match is found ! RichTextFX/richtextfx/src/main/java/org/fxmisc/richtext/GenericStyledArea.java Lines 823 to 826 in 74efc78
The solution then is to somehow make getParagraphs() to likewise contain the merged objects, and not necessarily the originally submitted edit. |
…on (issues FXMisc#777 and FXMisc#788) (borrowed code from ReactFX, which uses same license as RichTextFX)
@Jugen I have a fix for this issue in PR #795, which also fixes #788 Earlier today I had a look at #788 and later at this issue and noticed that both issues are related somehow to The problem was that But this is not wanted because it keeps old outdated paragraphs and drops newly added paragraphs if the paragraph text and styling is equal. The solution is to use a Below is some detailed information how I used println's to see whats going on: I've added println's to the main constructor of class System.out.println("PARA "+System.identityHashCode(this)); To System.out.println("vis "+System.identityHashCode(visibleP));
for (int index = 0; index < getParagraphs().size(); index++) {
System.out.println(" "+index+": "+System.identityHashCode(getParagraph(index)));
} and to for (...) {
p(mod);
mod = mod.trim();
p(mod);
...
} Here is private void p(MaterializedListModification<Paragraph<PS, SEG, S>> mod) {
System.out.println("MOD from "+mod.getFrom());
System.out.print(" added "+mod.getAddedSize()+":");
mod.getAdded().stream().forEach(p -> System.out.print(" "+System.identityHashCode(p)));
System.out.println();
System.out.print(" removed "+mod.getRemovedSize()+":");
mod.getRemoved().stream().forEach(p -> System.out.print(" "+System.identityHashCode(p)));
System.out.println();
} When you run test get_first_visible_paragraph_index_with_all_blank_lines, which fails without the fix, you get following output:
You see that there are created four paragraphs. The first in the constructor of Below is the modification before
Below is the modification after "buggy"
And here is the output of
And here is the output with fixed
In the above case, the new
|
Expected Behavior
Shouldn't throw exception but return the index of the paragraph.
Actual Behavior
Sometimes when I call this method it reaches:
throw new AssertionError("Unreachable code");
As much as I can tell the problem is that the element in the visibleParagraphs is the same as the one in the paragraphs but they are not the same reference therefore the search can't find it. I have no idea how is this possible.
Reproducible Demo
Unfortunately I only have this rarely...
Environment info:
The text was updated successfully, but these errors were encountered: