Page 1 of 1

Need Help with Arrays of Cubes

Posted: Mon Sep 18, 2006 1:32 am
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);
	}

Posted: Mon Sep 18, 2006 2:35 am
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...

Posted: Mon Sep 18, 2006 7:53 am
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.

Posted: Mon Sep 18, 2006 8:21 pm
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

Posted: Sat Sep 23, 2006 8:26 pm
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?

Posted: Sat Sep 23, 2006 8:40 pm
by hybrid

Code: Select all

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