[fixed] CGUIEditBox - selecting text causing segfault

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
ceyron
Posts: 63
Joined: Tue Mar 03, 2009 5:10 pm
Location: Bucuresti, România

[fixed] CGUIEditBox - selecting text causing segfault

Post by ceyron »

[UPDATE]
Just tried it on windows and it works fine, seems to be only crashing on linux...but why :shock:

When selecting a text in the edit box it will, sometimes(everytime if the edit box has a large text into it) cause the application to crash.
Here is a test case (try selecting the text in the edit box all the way to the end):

Code: Select all

//Irrlicht version: 1.7.2
//OS: linux

#include <cstdlib>
#include <irrlicht.h>

using namespace std;
using namespace irr;
using namespace gui;
using namespace scene;
using namespace video;

/*
 * 
 */
int main(int argc, char** argv)
{
    IrrlichtDevice *device = createDevice(video::EDT_OPENGL, core::dimension2d<u32> (800, 600), 32, false, false, false);

    if (!device)
        return EXIT_FAILURE;

    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
    gui::IGUIEnvironment* guienv = device->getGUIEnvironment();

    gui::IGUIEditBox* e1 = guienv->addEditBox(L"", core::rect<s32>(50,150,250,240),true);
    e1->setText(L"Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
                          "Aliquam venenatis leo vitae lorem tristique non congue felis blandit.\n"
                          "Aliquam et libero sapien. Nullam a adipiscing nunc");
    e1->setAutoScroll(true);
    e1->setMultiLine(true);
    //e1->setMax(1024);

 while (device->run())
    {
        driver->beginScene(true, true, video::SColor(0xFFA0A0A0));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();
    }

    return EXIT_SUCCESS;
}
Here's what i get in the terminal, so it's crashing in irrString.h on line 330

Code: Select all

TestEditbox: ../../include/irrString.h:330: T& irr::core::string<T, TAlloc>::operator[](irr::u32) [with T = wchar_t, TAlloc = irr::core::irrAllocator<wchar_t>]: Assertion `!(index>=used)' failed.
Aborted
Press [Enter] to close the terminal ...
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

What about the strack trace? Can you see which methods are called in between?
ceyron
Posts: 63
Joined: Tue Mar 03, 2009 5:10 pm
Location: Bucuresti, România

Post by ceyron »

This is what NetBeans shows in call stack
Image
Image
ceyron
Posts: 63
Joined: Tue Mar 03, 2009 5:10 pm
Location: Bucuresti, România

Post by ceyron »

OK i included irrlicht source directory and copied both CGUIEditbox.h & CGUIEditbox.cpp into my project folder the only lines that i changed from the code posted above are

Code: Select all

#include "CGUIEditBox.h" //after #include <irrlicht.h>

//and creating the element like this
 gui::IGUIEditBox* e1 = new gui::CGUIEditBox(L"",true,guienv,guienv->getRootGUIElement(),-1, core::rect<s32>(50,150,250,240));
...and surprisingly it works, so i thought maybe i linked against another version of irrlicht but i didn't, i rebuild irrlicht and tested again but edit box only works when i do like i mentioned, i have no idea what's going on!

Can someone else running linux test this please...
Image
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, this is the cursor draw code. Since the underflow is tested, it seems that the cursor position is either too large, or the text string is broken. Couldn't test it live for now, but will do so.
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Should I take this one? Crashes only with mouse-selection. It looks like getCharacterFromPos in getCursorPos shouldn't take Text, but probably txtLine.

edit: Hm, that is the problem, but there is something else strange going on. The \n seems to be replaced by a space character...
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
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe this happens in order to make our own line breaks instead of user forced ones? And yeah, you can have it. I suck at GUI :wink:
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ok, I fixed the crash in svn releases 1.7 branch. Thanks for test-case.

The other problem is independent, I was just confused because it also looked like a selection problem at first. I put that one on my todo for another evening.
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
ceyron
Posts: 63
Joined: Tue Mar 03, 2009 5:10 pm
Location: Bucuresti, România

Post by ceyron »

Works now, thank you for fixing it
Image
Post Reply