Game Development Community

T3D 2.0 - RenderMeshExample Bug

by Demolishun · in Torque 3D Professional · 01/08/2013 (8:00 pm) · 5 replies

Build: T3D 2.0
Platform: Windows 7 64 bit
Target: T3D mission

Issues:
The RenderMeshExample object in renderMeshExample.cpp/.h will not display a the assigned material after being saved to a mission and the mission restarted.

Steps to Repeat:

  1. Add RenderMeshExample object to mission.
  2. Assign a material to the object and see the object is indeed visible.
  3. Save the mission.
  4. Quit to main menu.
  5. Start mission again.
  6. Observe that the RenderMeshExample object is no longer visible.
  7. Enter editor and see that the object material is set, but it is not displaying this material.

Observations:
Upon closer inspection I found that the code is failing on the "isProperlyAdded" call:
void RenderMeshExample::unpackUpdate(NetConnection *conn, BitStream *stream)
{
   // Let the Parent read any info it sent
   Parent::unpackUpdate(conn, stream);

   if ( stream->readFlag() )  // TransformMask
   {
      mathRead(*stream, &mObjToWorld);
      mathRead(*stream, &mObjScale);

      setTransform( mObjToWorld );
   }

   if ( stream->readFlag() )  // UpdateMask
   {
      stream->read( &mMaterialName );

      if ( isProperlyAdded() )       
         updateMaterial();
      else
         Con::errorf("RenderMeshExample::unpackUpdate - not properly added.");
   }
}

Suggested Fix:
For a temporary fix I have removed the "if ( isProperlyAdded() )" check so I can continue to work. I have seen no adverse effects in doing this. I have no idea why a ghosted object would fail the isProperlyAdded check.

Update:
This fixes this issue:
bool RenderMeshExample::onAdd()
{
   if ( !Parent::onAdd() )
      return false;

   // setup material
   if( isClientObject() ){
      updateMaterial();
   }

   // Set up a 1x1x1 bounding box
   mObjBox.set( Point3F( -0.5f, -0.5f, -0.5f ),
                Point3F(  0.5f,  0.5f,  0.5f ) );

   resetWorldBox();

   // Add this object to the scene
   addToScene();      

   return true;
}

About the author

I love programming, I love programming things that go click, whirr, boom. For organized T3D Links visit: http://demolishun.com/?page_id=67


#1
01/09/2013 (2:33 pm)
I fixed the bug report to be more inline with guidelines.
#2
01/11/2013 (11:33 am)
Update:
I have created an object modeled after the RenderObjectExample (in same folder as RenderMeshExample). This one I have added the ability for rendering its own texture. This is for a custom object debugging. In the onAdd() function call I am running the updateMaterial() function and checking that it is on the client only. This does not seem to have adverse effects and it does work. So maybe the fix for this is to run the updateMaterial() in the onAdd() call on the client. I am guessing the initial network update that is failing does not happen again because there is no "tick" on the RenderMeshExample object.
#3
01/12/2013 (1:17 am)
Arg, I remember fixing this for the GLOVES demo I made for that competition, but I've lost that codebase! (I know, right? :P) Did you try running updateMaterial() in onAdd? That seems familiar.
#4
01/12/2013 (4:37 am)
Yep, that is what seems to work:
// setup material
if( isClientObject() ){
  updateMaterial();
}

I think the main issue is the network update is occurring before the ghosted object is added to the scene. That is my best guess.
#5
04/22/2013 (1:46 am)
Thanks for the fix, saved me some time.

One more thing... it is causing the game to freeze on exit.