[20_13] Do not add duplicated values to copy_always to avoid stack overflow #2205
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Add check before adding new values to
edit_interface_rep::copy_always
in functionedit_interface_rep::apply_changes()
.New rectangle will be added to
copy_always
ifcopy_always
is empty/nil or the first item ofcopy_always
is not equal to newly added value.Why
Since
apply_changes()
will be called when the window receives any event,copy_always
will become very large and cause stack overflow when it's cleared.The
copy_always
is a linked list and when it's cleared, the destructor is called from head to tail recursively, causing stack overflow.How to test your changes?
That's the potential risk: I can only test it on Windows with few scenarios, I don't know the result in Linux, Mac.
already run
xmake run --yes -vD --group=tests
andxmake run --yes -vD --group=integration_tests
The investigations below are all in Windows environment.
Where is the code to clear
copy_always
?In
edit_interface_rep::scroll_to()
andedit_interface_rep::set_extents()
, by usingcopy_always = rectangles ()
.When will
copy_always
be cleared?scroll_to()
is called when the cursor is moved out of current view.I can't add breakpoint in
set_extents()
, I don't know when will it will be called.What's the purpose of
copy_always
?The comment says it's used for wiping out cursor.
However I think it doesn't do anything now.
I comment out the code that uses it, get nothing wrong.
But removing it is more dangerous.
Where is
copy_always
used?In
edit_interface_rep::draw_pre()
andedit_interface_rep::draw_with_shadow()
.In
draw_pre()
, it will go through all rectangles incopy_always
and callwin->put_shadow()
, but it doesn't draw anything at all.Because in
qt_renderer_rep::put_shadow()
,painter == static_cast<qt_renderer_rep*> (ren)->painter
is true and returns directly.In
draw_with_shadow()
, it's only used ifgui_interrupted()
returns true, butgui_interrupted()
doesn't return true in my machine.These shadow functions are related to the double buffering, the behavior may be different in other OS.
In summary, I don't think it's necessary to store all the old rectangles in
copy_always
.The latest ones
ocr
(old cursor) andncr
(new cursor) should be enough for cursor drawing stuff.