Edit: Odd segmentation fault....

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Edit: Odd segmentation fault....

Post by Paddon »

Hey all,

I keep getting a segmentation fault and I have traced it to the addToolbar line in my code. I see no reason as to why this should be happening but it is. Here is my createGUI() function from my GUI class, the GUIEnviroment is initialized in the GUI class constructor. Please ignore all the printf()'s as those were to help me locate where the problem was occuring.

Code: Select all

void Gui::createGUI(void)
{ printf("Creating GUI..\n"); //last printf to execute
  IGUIToolBar* bar = env->addToolBar(); //This is where the problem must be occuring
  printf("Toolbar Created..\n");
  env->addStaticText(L"Constant Path: ", core::rect<s32>(8,10,90,25), false);
  IGUIEditBox* namebox = env->addEditBox(L"Test/X", core::rect<s32>(100,8,240,25), true, bar, 901);
  printf("Const. Path Box Created..\n");
  env->addStaticText(L"Start#:", core::rect<s32>(250,10,300,25), false);
  IGUIEditBox* range1box = env->addEditBox(L"1", core::rect<s32>(310,8,350,25), true, bar, 902);
  printf("Range1 Box Created..\n");
  env->addStaticText(L"End#: ", core::rect<s32>(360,10,410,25), false);
  IGUIEditBox* range2box = env->addEditBox(L"1", core::rect<s32>(420,8,470,25), true, bar, 903);
  printf("Range2 Box Created..\n");
  IGUICheckBox* sphere_check_box = env->addCheckBox (true,core::rect<s32>(490,8,510,25) , bar, 400, L"Spheres");
  IGUICheckBox* box_check_box = env->addCheckBox (false,core::rect<s32>(530,8,550,25), bar, 400, L"Boxes");
  printf("Check Boxes Created..\n");
  IGUIButton* launchbutton = env->addButton(core::rect<s32>(570,8,600,25), bar, 1101, L"Launch");
  printf("Launch Button Created..\n");
  fpstext = env->addStaticText(L"", core::rect<s32>(850,8,900,25), true);
  timetext = env->addStaticText(L"", core::rect<s32>(910,8,1010,25), true);
  frametext = env->addStaticText(L"", core::rect<s32>(1020,8,1150,25), true);
  printf("Static Text's Created..\n");

  IGUIButton* helpbutton = env->addButton(core::rect<s32>(1750,8,1790,25), bar, 1102, L"Help");
  IGUIButton* prefbutton = env->addButton(core::rect<s32>(1650,8,1740,25), bar, 1103, L"Preferences");
  printf("Help and Pref. Buttons Created..\n");



  IGUISkin* skin = env->getSkin();
  printf("Got Skin..\n");
  IGUIFont* font = env->getFont("../include/fonthaettenschweiler.bmp");
  printf("Got Font..\n");

    skin->setFont(font);
    printf("Font Set..\nBeginning Alpha Loop\n");

  	for (s32 k=0; k<gui::EGDC_COUNT ; ++k)
	{
 		SColor col = env->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)k);
		col.setAlpha(255);
		env->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)k, col);
	}
  printf("Alpha Loop Finshed..\n");


  stringw capstr = L"Visualization";
  device->setWindowCaption(capstr.c_str());
  printf("Window Caption Set..\nGUI Finished\n");

}
Any help as to why this creation of a toolbar is giving me a segmentation fault would be greatly appreciated.
Last edited by Paddon on Wed Aug 16, 2006 2:13 pm, edited 1 time in total.
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
Mikenoworth
Posts: 78
Joined: Sat May 27, 2006 9:24 pm
Location: Logan, UT

Post by Mikenoworth »

Is env valid? Make sure it is valid.

You could either check it in debug, or add code:

Code: Select all

if(!env)
{
    printf("oopsie, env is bad.\n");
    return;
}
Stout Beer
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Post by Paddon »

Nope, I have that exact check in my constructor but it still is not working.

Could it have something to do with the fact that I create a pointer to my GUI class, and then execute it?

i.e. I implement it as follows:

Gui *interface;

interface->createGUI();

Considering nothing else seems wrong this is the only solution I can think of, but it doesn't seem plausible.
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Post by Paddon »

Well I commented out everything in my createGUI function thus it seems that I was wrong about the toolbar being the issue. It is somehow my implementation of this function and/or class.....
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
Warchief
Posts: 204
Joined: Tue Nov 22, 2005 10:58 am

Post by Warchief »

Code: Select all

// This code will fail. Pointer is not valid
GUI* interface;
interface->createGUI();

// This will work
GUI* interface = new GUI();
interface->createGUI(); 

// This will work
GUI interface;
interface.createGUI(); 
Are you creating GUI instance?
Halan
Posts: 447
Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:

Post by Halan »

looks similiar like a problem i got with my event reciever (still didnt solve it)

http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=14135

greets,
halan
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Post by Paddon »

Interesting, it makes sense it is a null pointer, but can anyone recommend a good debugger as I do not have one right now.
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
Mikenoworth
Posts: 78
Joined: Sat May 27, 2006 9:24 pm
Location: Logan, UT

Post by Mikenoworth »

:!: Look at Warchiefs reply! He is right!

Code: Select all

Code: 

// This code will fail. Pointer is not valid 
GUI* interface; 
interface->createGUI(); 

// This will work 
GUI* interface = new GUI(); 
interface->createGUI(); 

// This will work 
GUI interface; 
interface.createGUI(); 


Are you creating GUI instance?
Stout Beer
Paddon
Posts: 43
Joined: Thu Jul 06, 2006 4:09 pm

Post by Paddon »

I didn't ignore his post and I did change it to an instance, but I still get the fault.

Code: Select all

// This will work
GUI interface;
interface.createGUI();
- Jeff Paddon
Undergraduate Research Assistant
Physics Department
St. Francis Xavier University
Mikenoworth
Posts: 78
Joined: Sat May 27, 2006 9:24 pm
Location: Logan, UT

Post by Mikenoworth »

Have you found a solution to your problem ?? What c++ editor are you using?
Stout Beer
RapchikProgrammer
Posts: 279
Joined: Fri Dec 24, 2004 6:37 pm

Post by RapchikProgrammer »

if you are using namespace gui; and then declaring a variable or class with the name gui it will give some errors! And the only solution i thought of is already posted by warchief!
Post Reply