Strange Corrupted Text in GUI after SetPosition() call

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Aggie
Posts: 7
Joined: Sun Jul 22, 2012 11:56 pm

Strange Corrupted Text in GUI after SetPosition() call

Post by Aggie »

Hi,

I'm new to Irrlicht, and I'm making a simple GUI to load some meshes. I've not had any problems except after I make a call to SetPosition() on some meshes.

Here's the gist of my main function:

Code: Select all

int main()
{
  IrrlichtDevice* device;
  IVideoDriver* driver;
  IGUIEnvironment* guienv;
  device = createDevice(driverChoiceConsole(),dimension2d<u32>(800,600), 16, false, false, false, NULL);
  if (!device){
    cerr << "Error: Could not create device" << endl;;
    return 1;
  }
  device->setResizable(true);
 
  driver = device->getVideoDriver();
  guienv = device->getGUIEnvironment();
 
  IGUISkin* skin = guienv->getSkin();
  IGUIFont* font = guienv->getFont("../../media/fonthaettenschweiler.bmp");
  if (font) skin->setFont(font);
  skin->setFont(guienv->getBuiltInFont(),EGDF_TOOLTIP);//have the tooltip font be the built-in one
 
  guienv->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
      L"Quit", L"Exits Program");
  guienv->addButton(rect<s32>(10,280,110,280 + 32), 0, GUI_ID_LOAD_SCENE_BUTTON,
      L"Load Scene", L"Choose .scene file to load");
guienv->addButton(rect<s32>(10,320,110,320 + 32), 0, GUI_ID_LOAD_INPUT_BUTTON,
      L"Load Input", L"Choose input file to load");
  guienv->addButton(rect<s32>(10,360,110,360 + 32), 0, GUI_ID_LOAD_STATES_BUTTON,
      L"Load States", L"Load vector of states");
  IGUIButton* renderB = guienv->addButton(rect<s32>(10,400,110,400 + 32), 0,
      GUI_ID_RENDER_BUTTON,
      L"RENDER", L"Begin rendering");
  renderB->setEnabled(false);
  AppContext context;
 ..some unimportant stuff
 
  MyEventReceiver receiver(context);
  device->setEventReceiver(&receiver);
  while(device->run() && driver){
    if (device->isWindowActive()){
      driver->beginScene(true,true,SColor(0,200,200,200));
      device->getSceneManager()->drawAll();
      context.scene->UpdateScene(); //will eventually call setPosition on some meshes, causing my problem
      guienv->drawAll();
 driver->endScene();
 
    }
    else device->yield();
  }
  device->drop();
  return 0;
}

This code works fine until I click the button I defined as "Load States". What Load States does is essentially use pre-computed position/rotation information about objects in the scene, and just calls SetPosition() and SetRotation on them. I have narrowed down the problem to be in the SetPosition call:

Here's the gist of the function:

Code: Select all

for(int i=0; i<(int)states.size(); i++) {
        core::vector3df vec = positions.at(m_frameNum).at(i);
        core::vector3df rot = rotations.at(m_frameNum).at(i);
        states[(irr::s32)i]->setRotation( rot );
        states[(irr::s32)i]->setPosition(vec);
}
After this code runs, all my buttons have junk labels and tooltiptext.
I've looked at the actual values in vec, and there's no "nan" or junk values like that. In fact, I determined that the issue is that SetPosition seems to fail when I give it a value greater than 120.0 in Z (EDIT: The actual failure range is from 120.0 to 470.0. Any value inside [non-inclusive] causes the gibberish text, while other values are fine). This is a problem because I need to set Z values of at least 260.0.

I don't see this issue when I use large values in X or Y; only for Z. 119.0 works, 120.0 works, but 121.0 and up causes the gibberish text on my buttons. It doesn't show the same issue when I go negative either; -121.0 works just fine.

Note: the SetPosition() call only results in junk text on my GUI; otherwise it correctly sets positions.

Can anybody shed light on this?

Edit: Some more information: I'm running Irrlicht 1.7.2 on Ubuntu 12.04 on a 64-bit machine. My graphics card is an integrated nVidia one. I'd be happy to provide more detailed specs on my system if anyone thinks it will help.
Aggie
Posts: 7
Joined: Sun Jul 22, 2012 11:56 pm

Re: Strange Corrupted Text in GUI after SetPosition() call

Post by Aggie »

I've continued to attempt to debug this problem, and something I've noticed is that when I take out all calls to setRenderTarget(), the GUI appears fine after setPosition() calls...which is weird that I would only see an error elsewhere in the program's execution, and for such a specific thing.

Regardless, the issue is definitely with setting the renderTarget. I'll continue looking into this to see if I can find a solution. If/when I do, I'll post it here.

-Aggie
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Strange Corrupted Text in GUI after SetPosition() call

Post by hendu »

setMaterial(getMaterial2D());

Known issue, use that workaround before GUI rendering.
Aggie
Posts: 7
Joined: Sun Jul 22, 2012 11:56 pm

Re: Strange Corrupted Text in GUI after SetPosition() call

Post by Aggie »

Wow, thanks hendu!

For others that may be reading this thread, the call he is talking about goes in your main loop before you call IGUIEnvironment's drawAll() function. e.g.

Code: Select all

 
while(device->run() && driver){
    if (device->isWindowActive()){
      driver->beginScene(true,true,SColor(0,200,200,200));
      device->getSceneManager()->drawAll();
      driver->setMaterial(driver->getMaterial2D());
      guienv->drawAll();
      driver->endScene();
    }
   else device->yield();
  }
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Strange Corrupted Text in GUI after SetPosition() call

Post by hybrid »

I remember probelms with render targets, but here it seems just a common scene/gui render loop. Not sure why there would be a problem with the 2d material setup.
Post Reply