IGUIImage problems

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
UpandComing
Posts: 5
Joined: Tue Dec 06, 2011 3:12 pm

IGUIImage problems

Post by UpandComing »

I'm having issues using IGUIImage and to be truthful I'm having difficulty understanding it in general.

So here is where I'm at:

Code: Select all

gui::IGUIImage* image;
video::ITexture* background;
 
image->setImage(background); 
In my head this should work. It compiles fine but causes a run time error for NullAccessViolation for what i assume is because the GUIEnvironment that IGUIImage is using is null. (Please correct me if I'm wrong)
Looking through the method lists i find no methods to set the GUIEnvironment and also i can't use the new keyword because the class is abstract and cannot be instantiated. I assume it's abstract with pure virtual functions for the purpose of creating a custom GUIImage class and deriving from this?

On a whim i did attempt to initialize the IGUIImage's GUIEnvironment like this:

Code: Select all

image = device->getGUIEnvironment(); 
but to no avail.

Could someone fill in the blanks for me here? I'm not a noob to the C++ language but the reason for much of this engine seem unclear or vague to me.

Thanks in advance
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: IGUIImage problems

Post by zerochen »

you dont init either the image nor the texture

eg
IGUIImage* icon = env->addImage(recti(0, 0, 10, 10), parent, id);
icon->setScaleImage(true);
icon->setImage(driver->getTexture("aTexture.png");
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: IGUIImage problems

Post by CuteAlien »

Please try to understand the examples, that's what they are there for. Example 05 does show how to create a gui - including an image.

What you have above are 2 unitialized pointers which means they will point to a random place in memory. What you are doing when trying to call any functions for those is that you are telling the processor to run some randomly initialized code which in around 99.99% of the cases will simply crash (and probably not doing anything good in the other 0.01%). You always need to create objects in memory first before you can do anything with them. The examples explain how you do that stuff in Irrlicht (basically you create first a device, that device has then a gui-environment which you can use to create further gui-elements).
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
Radikalizm
Posts: 1215
Joined: Tue Jan 09, 2007 7:03 pm
Location: Leuven, Belgium

Re: IGUIImage problems

Post by Radikalizm »

UpandComing wrote:I'm not a noob to the C++ language but the reason for much of this engine seem unclear or vague to me.
Not trying to be a dick here, but seeing the nature of the error you made I kind of get the feeling you are
Using an uninitialized pointer is a huge error in C++, no matter which library you're using
Post Reply