[fixed]Bug with pasting text into edit box

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
Reiko
Posts: 105
Joined: Sun Aug 16, 2009 7:06 am
Location: Australia

[fixed]Bug with pasting text into edit box

Post by Reiko »

When you paste text into a multi-line edit box, which the text you are pasting has more than one newline in it, this breakpoint gets triggered in irrstring.h:

Code: Select all

        //! Direct access operator
        T& operator [](const u32 index)
        {
                _IRR_DEBUG_BREAK_IF(index>=used) // bad index
                return array[index];
        }
and going back on the stack trace visual studio points to the bottom line of this:

Code: Select all

                // draw cursor
 
                if (WordWrap || MultiLine)
                {
                        cursorLine = getLineFromPos(CursorPos);
                        txtLine = &BrokenText[cursorLine];
                        startPos = BrokenTextPositions[cursorLine];
                }
                s = txtLine->subString(0,CursorPos-startPos);
                charcursorpos = font->getDimension(s.c_str()).Width +
                        font->getKerningWidth(L"_", CursorPos-startPos > 0 ? &((*txtLine)[CursorPos-startPos-1]) : 0); <=== this one
I think it has something to do with line feed (\r) or maybe characters that can't be drawn in general, or maybe characters that a string won't keep? and the edit box's cursor position.

If I paste 2 lines of text into an empty edit box (so only 1 line break), there's no error.
If I paste 3 lines of text into an empty edit box, it stops.
If I type "abc" into the box, then put my cursor to the start of the line, then paste 3 lines of text, it pastes correctly and doesn't crash BUT my cursor ends up 2 places to the right of where it should be (cursor is now on the "c")
Same goes for if I type "abcde" into the box, then put my cursor to the start of the line, then paste text containing 4 new lines, my cursor ends up 5 places to the right of where it should be (cursor is now on the "e")
But if there are too little chars for the cursor to be incorrect by (eg. "abcde" and pasting 10 lines of text) then the program will stop.

Note that I'm on windows so a newline for me is \r\n.

Now if I use the copyToClipboard function in Irrlicht to copy a string of 10 lines, using \n instead of \r\n for newlines, then paste it into an empty edit box, then no error occurs and it works properly.

So the problem is most likely related to the handling of \r and where its trying to draw the cursor position but I could be wrong.
Reiko
Posts: 105
Joined: Sun Aug 16, 2009 7:06 am
Location: Australia

Re: Bug with pasting text into edit box

Post by Reiko »

Well I modified the engine to remove all \r from the text when pasting from clipboard, now it works fine and no crash, and the cursor position is also correct. This is good enough for me since my program is windows only, but this obviously wouldn't be good for mac users, so I'll let you guys find a better solution. Sorry I can't be of more help than that but while my knowledge of the parts of the engine that I use is ok, I don't know it fully.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bug with pasting text into edit box

Post by CuteAlien »

Ok, thanks. I will test it later on. Just one question - which version are you using right now? Because I fixed some crashes in the editbox recently which occured with multiline (but I have not tested this one).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Reiko
Posts: 105
Joined: Sun Aug 16, 2009 7:06 am
Location: Australia

Re: Bug with pasting text into edit box

Post by Reiko »

Still using rev 3876 right now. The current as I see is 3884.

While we are on the topic, will there be functions like setCursorPos() soon? This would be useful for me because I have some edit boxed which are enabled, but I dont allow writing in them. So whenever the user types in it, I set the text back to what I want it to be (this allows the user to highlight and copy/paste, but not edit the text). I also have some boxes where the user can input a number (for colors) between 0 and 255. The program makes sure the value is in the range of 0-255. So if the box has 255 in it already and they start typing in it, the text stays at 255 because I'm keeping it at that, but the cursor still moves. It would be nice to have the cursor position locked while typing in it and the value isnt changing, so a get and setCursorPos() would allow me to do this. I know there are spinboxes for values, but in this case it didn't seem to be what I wanted so I used an edit box.

Or even a 'nonchangeable' setting on edit boxes would be nice too, to give the behaviour like I'm talking about without me having to code it myself.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bug with pasting text into edit box

Post by CuteAlien »

Yeah, I fixed so many editbox problems recently (and still some open) because I wanted to add setCursorPos. But before doing that I wrote the tests and those showed up some bugs which editboxes already had, including crashes... so I got stuck on working on those bugs first. And well ... last days I spend most hours on hunting the problem you reported with modal-dialog focus (got it fixed, but the fix needed focus-changes which then broke the gui-menues and I haven't got around yet to fixing those and will have to move fixes anyway into trunk as it turned out to be too much change to include into 1.7 bugfix release...). But as soon as I got those focus-bugs solved and then fixed other editbox bugs like this one (and the colors which I messed up while fixing another bug...) I'll be back to setCursorPosition. Which is unless I run into more bugs by then :-) Well, maybe I fix the pointInTriangle bug first as that's more urgent... but immediately after that!

(and I'm still considering rewriting the breakText completely as it should really be in a textsplitter class as it is needed in several other gui-elements (everything that can receive text really, like listboxes, guitables and maybe even buttons) and mostly implemented already 3 times in similar but slightly different ways, but before doing that I have to write some speed-tests as there is a problem with that in editboxes with lots of text and I'm not sure yet if it's causes only by drawing or if textsplitting itself is part of the trouble)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Reiko
Posts: 105
Joined: Sun Aug 16, 2009 7:06 am
Location: Australia

Re: Bug with pasting text into edit box

Post by Reiko »

Sounds pretty good, good luck with that :)
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Bug with pasting text into edit box

Post by CuteAlien »

Fixed now in r4053 for in releases/1.7 branch, merge with trunk will follow soon.
Bug was that editbox removes \r in breakText and had to changed the cursorpos when doing so.
Actually I think the better solution would be if breakText wouldn't do that at all, but I don't want to risk changing that in a stable release branch as users might already expect that behavior.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply