Need Help with Arrays of Cubes

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
jadams
Posts: 3
Joined: Mon Sep 18, 2006 1:21 am

Need Help with Arrays of Cubes

Post by jadams »

My C++ skills are weak so please forgive this noob post.

I am trying to create and render an array of textured cubes. The wierd thing is, while in debug mode, the code runs and renders the cubes without textures. The console shows an error message that texture <path> cannot be loaded.

When I run the executable outside of the IDE, the exe crashes. The console indicates that the texture is not found. The bitmap is in the correct path.

Here is the relavent portion of code, can someone please let me know what I am doing wrong here? Thanks in advance.

Code: Select all

irr::core::array<scene::ISceneNode*> cubes(3);

	// create the cubes, set textures, position and
	// set lighting
	video::ITexture* cubeTex = driver->getTexture("wall.bmp");
	for (int i = 0; i < cubeCount; i++)
	{
		cubes[i] = smgr->addCubeSceneNode();
		cubes[i]->setPosition(vector3df( (float)(i * 10), 0, 0));
		cubes[i]->setMaterialFlag(EMF_LIGHTING, false);
		cubes[i]->setMaterialTexture(0, cubeTex);
	}
CK_MACK
Posts: 7
Joined: Mon Sep 18, 2006 12:57 am

Post by CK_MACK »

I am just a beginner, but from the looks of this line:
getTexture("wall.bmp");

that means it will get the texture Whereever the .EXE is compiled at...and thus the directory folder where the .exe currently is launched from.

(yes?)

So, if that's true... then that would mean you have "wall.bmp" in the same directory as your executable?

If not... you can change the location of your executable... or provide a directory path to your bmp...
getTexture("../../media/wall.bmp"); // for example

The above code is similar to the code provided in the examples...
However, you might also try the complete directory path...
MACK
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

And always check the pointer values before submitting a 0 pointer to some method. The renderers will always crash (and maybe even your whole system will die) with such pointers.
rikyoh
Posts: 14
Joined: Fri Sep 08, 2006 1:02 pm

Post by rikyoh »

If you are using Visual C++ and start your programm from the ide, it will run in the context of your project folder. Because you have stored your textures there, they are found.
But if you start the exe directly from one of the subfolders where it is created ("debug" and "release" by default) it will not find the textures (or other files). So you have to copy the exe into the project folder first...

Bye Riky
jadams
Posts: 3
Joined: Mon Sep 18, 2006 1:21 am

Post by jadams »

Thanks for the input guys.

It makes no difference where I place the texture I still cannot run the exe. This includes the directory the exe exists in. This is where I am trying to run it from.


@Hybrdid

And always check the pointer values before submitting a 0 pointer to some method. The renderers will always crash (and maybe even your whole system will die) with such pointers.

How do I check the pointer?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Code: Select all

ITexture* texture=getTexture("blah");
if (texture)
{
    // do something with the valid texture
}
Post Reply