Skip to content

Fix selection crash#3241

Merged
vadi2 merged 7 commits intoMudlet:developmentfrom
CriusMacOldenly:ttextedit-crash-bug
Dec 3, 2019
Merged

Fix selection crash#3241
vadi2 merged 7 commits intoMudlet:developmentfrom
CriusMacOldenly:ttextedit-crash-bug

Conversation

@CriusMacOldenly
Copy link
Copy Markdown
Contributor

@CriusMacOldenly CriusMacOldenly commented Nov 16, 2019

Brief overview of PR changes/additions

Put in a couple checks for bounds in front of every place I can imagine an out of bounds check is needed.

Motivation for adding to Mudlet

Other info (issues closed, discussion etc)

Fix #3239.

Put in a couple checks for bounds in front of every place I can imagine an out of bounds check is needed.
@CriusMacOldenly CriusMacOldenly requested a review from a team as a code owner November 16, 2019 15:31
@CriusMacOldenly CriusMacOldenly requested a review from a team November 16, 2019 15:31
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Nov 16, 2019

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@njs50
Copy link
Copy Markdown

njs50 commented Nov 16, 2019

no crashing on selecting text, but also no text was selected just a bunch of newlines (mac os). In my terminal i see this:

TTextEdit::getSelectedText(...) INFO - unexpectedly hit bottom of method so returning: "\n\n\n\n\n\n\n\n\n\n\n"

that happens anytime i select anything, with various amounts of \n that seems related to how much i selected

@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

Oh, I wasn't smart with what I did. I chose to break out of the loop upon detecting a crash condition rather than continue. Thank you for pointing this out. Each time it did this \n it would have originally crashed. :(

@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

Never mind my previous statement. I used the wrong sign to check the bounds condition, so it always broke the loop when the variable was within the bounds.
I tested by trying to copy text, but I never tried to paste the text. :(
I have now tested copying and pasting the text. It works now.

I had to stare at the code a long time to figure out what the sign should be. I'm getting confused in my old age.

Fixed the signs, and moved code around to return on what would have caused the crash rather than just break out of a loop and never return the selected text.
@vadi2 vadi2 changed the title Update TTextEdit.cpp Fix selection crash Nov 17, 2019
@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Nov 17, 2019

@CriusMacOldenly so you think the issue was with blank lines in the selection?

@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

I think the issue was I used the wrong sign when trying to check for out of bounds. As a result, the code thought in bounds checks were out of bounds fails, and thus didn't actually run the code needed to copy the text.
I also altered the code a bit so if an out of bounds does happen, it will return the text immediately.
I tested copy and paste just enough to show it actually works if done on one pane with ctrl and normal select.
This seems to fix the blank lines in selection.

Copy link
Copy Markdown
Member

@SlySven SlySven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 Unless my analysis is off the changes proposed here will have no effect other than wasting CPU cycles... 🙁

Crius MacOldenly added 2 commits November 22, 2019 21:01
I think this undoes all my changes.
Undo final change.
@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

This undoes all my suggested changes. The only way I can see the crash bug happening the way I tried to fix it, is if mudlet is running multithreaded, and mpBuffer can change while the code is within the function... which is crazy talk, I think.

try catch blocks and variable dumps.
@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

If this change doesn't work, we have problems. :(

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Nov 23, 2019

... is if mudlet is running multithreaded, and mpBuffer can change while the code is within the function...

ℹ️ Technically, Mudlet does run multi-threadedly - (for instance, the Qt networking library code runs in a separate thread) - however the Mudlet part of it is effectively a single thread and the things that can modify the TBuffer class (e.g. network data received from the MUD Game server) do so via slot methods (e.g. (void) cTelnet::handle_socket_signal_readyRead()) which are run in that thread!

TBH I am not sure we have drilled down to the cause of the selection crash that you are investigating.

I would note that there can be empty lines in the (QStringList) TBuffer::lineBuffer which means that for some values of y in mpBuffer->lineBuffer.at(y).size() the value returned will be 0 (mpBuffer->lineBuffer.at(y).isEmpty() will return true) and on those lines mpBuffer->lineBuffer.at(y).at(x) will seg. fault for any value of x. Similarly for the corner case of an empty TBuffer - e.g. for a newly created TConsole of any mType a call to mpBuffer->lineBuffer.size() will return zero and any use of mpBuffer->lineBuffer.at(y) will seg. fault...

(std::deque<std::deque<TChar>>) TBuffer::buffer is almost the same - however on empty lines - where there is no TBuffer::lineBuffer content there may well be a default constructed TChar present which gets inserted in this code in TBuffer::translateToPlainText(...):

            // Start a new, but empty line in the various buffers
            ++localBufferPosition;
            std::deque<TChar> newLine;
            buffer.push_back(newLine);
            lineBuffer.push_back(QString());
            timeBuffer.push_back(QString());
            promptBuffer << false;
            dirty << true;

so that calls to mpBuffer->buffer[y].empty() {TBuffer::buffer is an STL data container} ON AN EMPTY LINE will be false but calls to the corresponding mpBuffer->lineBuffer.at(y).isEmpty() {TBuffer::lineBuffer is an Qt data container so has some slight differences in accessor methods compared to STL ones} will return true! 😮

@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

We have not drilled down to the cause of the crashes. I was instructed to fix the crashes with little knowledge of why the crashes were happening, and no way to reliably duplicate the crash.

The best I can do is the try catch method I am suggesting, and I hope someone can send back the variable dump I've put in -- this'll at least explain why the crash is happening. Once I know why the crash is happening, I can better look at how to fix the crash.

@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

It looks like the MacOS builds failed. I don't know why though. :(

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Nov 24, 2019

Yeah - I'm getting the same error on a PR I have outstanding - seems (AFAICT) like we are trying to install a package (PCRE) which is already in the system - for this to cause a moan and error out instead of letting it through with a "package is already installed" warning I am guessing that we are trying to downgrade this - which is a bit odd... 😜

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Nov 24, 2019

Maybe. I guess the homebrew environment changed, and what we had before was a pinned pcre version - because upgrading it took way too long due to all the dependencies. So the fix now is to pin to the current version that's already provided.

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Nov 24, 2019

Maybe. I guess the homebrew environment changed, and what we had before was a pinned pcre version - because upgrading it took way too long due to all the dependencies. So the fix now is to pin to the current version that's already provided.

Nope - it was a too simplistic shell script that was matching an updated brew for pcre2 when we were checking a list for one matching pcre - I have the fix for this pending @vadi2 or @keneanung 's approval as some additional commits (which I will "squash and merge") in #3249 ...

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Nov 24, 2019

Okay have caused the macOs CI builds to rerun and they have passed now that development has been updated...

Fix crash condition reported at Mudlet#3239 (comment) .
@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

Crash condition described in #3239 (comment) which is caused by starting text selection on an empty line has now been fixed.

@vadi2
Copy link
Copy Markdown
Member

vadi2 commented Dec 3, 2019

Great - could you take out all the debugging code? Then we can out it into the release.

Removed the debug code as per Vadi2's request in Mudlet#3241 (comment) .
@CriusMacOldenly
Copy link
Copy Markdown
Contributor Author

Great - could you take out all the debugging code? Then we can out it into the release.

As per your request, the debugging code has been removed. I really hope all the crash bugs are fixed.

Copy link
Copy Markdown
Member

@vadi2 vadi2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully. Normal nature of rewrites though. :) thanks for fixing this! Appreciated!

@vadi2 vadi2 merged commit 01b817a into Mudlet:development Dec 3, 2019
@CriusMacOldenly CriusMacOldenly deleted the ttextedit-crash-bug branch December 3, 2019 09:37
dicene pushed a commit to dicene/Mudlet that referenced this pull request Feb 19, 2020
* Update TTextEdit.cpp

Put in a couple checks for bounds in front of every place I can imagine an out of bounds check is needed.

* Update TTextEdit.cpp

Fixed the signs, and moved code around to return on what would have caused the crash rather than just break out of a loop and never return the selected text.

* Update TTextEdit.cpp

I think this undoes all my changes.

* Update TTextEdit.cpp

Undo final change.

* Update TTextEdit.cpp

try catch blocks and variable dumps.

* Update TTextEdit.cpp

Fix crash condition reported at Mudlet#3239 (comment) .

* Update TTextEdit.cpp

Removed the debug code as per Vadi2's request in Mudlet#3241 (comment) .
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

Successfully merging this pull request may close these issues.

Mudlet crashes when highlighting text if new text scrolls in

4 participants