Texture on Animated Mesh not showing [SOLVED - threads]

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
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Texture on Animated Mesh not showing [SOLVED - threads]

Post by Rytz »

Weird problem here but with luck it might be something simple that I'm overlooking. I haven't always had this problem - it just came up recently. What's making me crazy is that I haven't changed any of the code that involves the loading of the nodes and their textures.

I've seen this problem but only when a texture file is missing or not loaded.

Below is the code that I am using to load an MD2 animated mesh with a simple texture (tutorial media stuff):

Sydney Code:

Code: Select all

        node = ptrClient->ercv3DMain->dvWindow->getSceneManager()->addAnimatedMeshSceneNode(
            ptrClient->ercv3DMain->dvWindow->getSceneManager()->getMesh("media/models/sydney.md2"), 
            ptrClient->ercv3DMain->nodeRoom, 123456, posTarget, core::vector3df(0, 0, 0), core::vector3df(1, 1, 1));

		node->setMaterialTexture(0, ptrClient->ptrVideo->irrVDriver->getTexture("media/models/sydney.bmp"));
		node->setMaterialFlag(video::EMF_LIGHTING, false);
		node->setMD2Animation(animCurrent);
Faerie Code:

Code: Select all

        node = ptrClient->ercv3DMain->dvWindow->getSceneManager()->addAnimatedMeshSceneNode(
            ptrClient->ercv3DMain->dvWindow->getSceneManager()->getMesh("media/models/faerie.md2"), 
            ptrClient->ercv3DMain->nodeRoom, 123456, core::vector3df(0, 0, 0), core::vector3df(0, 0, 0), core::vector3df(1, 1, 1));

		node->setMaterialTexture(0, ptrClient->ptrVideo->irrVDriver->getTexture("media/models/faerie.bmp"));
		node->setMaterialFlag(video::EMF_LIGHTING, false);
		node->setMD2Animation(animCurrent);
Nothing amazing here. Below is the console output for the code above:
Image

Here is the visual output:
Image

Both of these animated mesh nodes are being loaded right next to each other. Is there anything that I could be missing to make the texture for the faerie not appear?
Last edited by Rytz on Fri Jul 06, 2007 6:37 pm, edited 1 time in total.
Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Some more testing shows that the texture really is loaded:

Code: Select all

printf("\n\nfilename of texture: %s\n\n", node->getMaterial(0).Textures[0]->getName().c_str());

Command Line Result:
Image

Not sure what else to try here. Any suggestions appreciated.
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Try a different renderer.

Travis
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

And check with 1.3.1
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Vitek wrote:Try a different renderer.
Haven't tried that yet but I'll give it a shot and post the results.
hybrid wrote:And check with 1.3.1
Just updated to 1.3.1 and no change. I did lose my map's dynamic lighting though :(. Gonna have to go back and see what's up with that.
Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Hypothetical question: would trying to set the texture from a different thread be a possible cause?

I was able to get the texture loaded but only when I call setMaterialTexture() from a certain function / spot in my code (also the main thread). Unfortunately the spot isn't where I need it to be. The weirder thing is that there really isn't much difference in what's actually going on with the scene in either place (working / not working) other than the thread difference.

My project is large so it would be hard to post the all the code so I'm going to do a diagram tomorrow and post it. The only real difference in placement is that the call to setMaterialTexture() from a different thread is the one that isn't working.
Image
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You cannot do Irrlicht stuff in different threads. The whole management of ressources will throw up.
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

hybrid wrote:You cannot do Irrlicht stuff in different threads. The whole management of ressources will throw up.
What's the reason for this? I'm working with the same pointers. Plus the only function call that seems to not be working is the setMaterialTexture().
Image
hybrid
Admin
Posts: 14144
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

getTexture and all other stuff working with the Caches won't work either. You can even have situations where it works, but when you have some different scheduling, a second processor or another situation you will likely get race conditions which will give you bad pointers, wrong render states or something else which is not desired.
What's the layout of your thread jobs?
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

hybrid wrote:getTexture and all other stuff working with the Caches won't work either. You can even have situations where it works, but when you have some different scheduling, a second processor or another situation you will likely get race conditions which will give you bad pointers, wrong render states or something else which is not desired.
What's the layout of your thread jobs?
I only have 1 seperate thread (using pthreads). Irrlicht is on the main program thread and my network library is receiving packets on the seperate thread.

I don't know a whole lot about threading tbh. It works for me right now and has, until this point, not caused any problems. If there is a way I can set up my networking thread to make this work then I'd be more than happy to do it.
Image
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

Just a heads up that puting my setMaterialTexture() calls in the main thread fixed the problem. Thanks for the info all.

I'm still interested in knowing more about Irrlicht and threads though :).
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

I'm still interested in knowing more about Irrlicht and threads though.
Irrlicht itself is not thread safe, so you need to use a mutual exclusion device to make sure that no two threads are modifying internal data structuers simultaneously. i.e. one thread setting the texture and the other thread loading that texture, or one thread updating a list and another thread iterating over it.
I only have 1 seperate thread (using pthreads). Irrlicht is on the main program thread and my network library is receiving packets on the seperate thread.
You don't need to use a thread to do networking. If you are using one and don't want to worry about the threading issues internal to Irrlicht, you can setup a producer consumer queue. The network thread will read data off of the network and assemble it into a structure that has information about the packet and the packet data. It would then lock a mutex, put the packet onto a linked list, and then unlock the mutex.

Code: Select all

while (receiving_from_network)
{
  // packet is a handle for a network packet, perhaps reference
  // counted. you could use a pointer but you would need to
  // manage its lifetime explicitly with grab()/drop()...
  Packet packet = receive_network_packet();

  pthread_mutex_lock(&m_mutex);
  m_packets.push_back(packet);
  pthread_mutex_unlock(&m_mutex);
}
Your main thread, sometime in the main loop, would create a temporary list, lock the mutex, swap implementations with the existing list, unlock the mutex, and then process the packets. Kinda like this...

Code: Select all

// i'd use a core::list, but it doesn't support swapping
std::list<Packet> packets;

// hold mutex for as little time as possible
pthread_mutex_lock(&m_mutex);
packets.swap(m_packets);
pthread_mutex_unlock(&m_mutex);

// now process each packet here in the main thread
for_each(packets.begin(), packets.end(), process_packet);
packets.clear();
There are also patterns for efficiently processing network data in a single thread, so this might all be overkill depending on what network library you are using.

Travis
Rytz
Posts: 249
Joined: Wed Oct 25, 2006 6:05 am
Location: IL, USA
Contact:

Post by Rytz »

vitek wrote:There are also patterns for efficiently processing network data in a single thread, so this might all be overkill depending on what network library you are using.

Travis
C++ Sockets is the lib I'm using. Thanks for the info. I'll dive into this probably later tonight.
Image
Post Reply