I was trying to create my own gui and decided to have all the elements in the gui drawn by the main gui object, so there is a simple function that calls draw2DImage with each element's ITexture*. The problem is that once that is in a separate function it no longer works. It works fine when the actual call to draw2DImage is in the main loop, but for some reason, when it is in a function it breaks down.
Any ideas?
Problem with draw2DImage
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Sorry, I'm not psychic. Do you want to post your code?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 19
- Joined: Fri Nov 24, 2006 9:33 am
Prep
Main Loop
Here's the GUI::drawAll()
buttons is an std::vector<Button*>
Code: Select all
GUI mygui; //the main gui object
Button button(driver->getTexture("irrlichtlogo.jpg"),NULL,NULL,core::position2d<s32>(10,10)); //creates a button
mygui.addButton(&button);//adds the button to the gui
Main Loop
Code: Select all
while (device->run() && driver)
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true,true,video::SColor(255,0,0,0));
smng->drawAll();
mygui.drawAll();
//driver->draw2DImage(button.drawTexture, button.position);
// ^ the commented out part works
driver->endScene();
}
Code: Select all
void GUI::drawAll()
{
//buttons
for (unsigned i=0;i<buttons.size();i++)
driver->draw2DImage(buttons[i]->drawTexture, buttons[i]->position);
}
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
"Button button" creates an object on the stack, which you're then passing and storing by reference. Unless the stack remains intact up to the point where you access mygui.buttons, you'll be accessing garbage.
I'd suggest:
Remembering that you'll need to delete all of the buttons in mygui when you're done with them.
I'd suggest:
Code: Select all
Button * button = new Button(driver->getTexture("irrlichtlogo.jpg"),NULL,NULL,core::position2d<s32>(10,10)); //creates a button
mygui.addButton(button);//adds the button to the gui
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 19
- Joined: Fri Nov 24, 2006 9:33 am
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
Then I suggest that you post your entire source, as I'm not going to start guessing what you mean by "did not work".
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
-
- Posts: 19
- Joined: Fri Nov 24, 2006 9:33 am
This is most of the source. I've haven't included the classes but they only have the definitions of the variables and function prototypes. The project is barely beginning and I wanted to start with a basic GUI of my own.
In terms of "not working" - I mean I get the "Do you want to send a report to microsoft" type of window. It is not a compile/linker error. When I try to debug the program, it crashes everything, including the Visual Studio and I have to end the devenv.exe process.
In terms of "not working" - I mean I get the "Do you want to send a report to microsoft" type of window. It is not a compile/linker error. When I try to debug the program, it crashes everything, including the Visual Studio and I have to end the devenv.exe process.