If the top line is wrapped, then after moving down the render, lines will not be adjusted properly. Visual cursor is at the end, and actual at n-old_top_line_wraps line.
The solution can probably be found by experimenting with moving up/down by a number of top's wraps when moving the render.
In release mode, cursor does not behave properly when wrapping or inserting anything into a wrapped line. It moves down for a moment, then moves back up and ends up in a different place than it's supposed to.
If line gets wrapped by inserting chars in the middle it does not behave as it's supposed to, i.e. wrap counters do not get incremented, cursor jumps away at the edges etc.
The reason is probably somewhere in the handle_insert_char logic.
With lines like: aaaaa aa aa aaaaaa
When moving down cursor jumps from the second line to the last one because of stored column. The probable fix is to add some guards in moving down loops so that they stop at the end of the line.