Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: TVActor.duplicate() and setTexture (bug ?)  (Read 1304 times)
akd
Customers
Community Member
*****
Posts: 53


WWW
« on: August 13, 2009, 02:22:52 AM »

Hi everyone,

after resolving my duplication problem, thanks to Sylvain, I encounter another problem with actor duplication and setTexture.

Here is the code that realise actor initialisation and texture initialisation.

Code:
TVActor newactor;
            if (!_TVactor_namelist.ContainsKey(filename))
            {
                //this kind of mesh is not loaded, we load it
                newactor = Core.graphic.scene.CreateActor(filename);
                if (filename.EndsWith(".tva") || filename.EndsWith(".TVA"))
                {
                    if (texture.Equals(""))
                    {
                        newactor.LoadTVA(Core.basepath + filename, true, true);
                    }
                    else
                    {
                        newactor.LoadTVA(Core.basepath + filename, false, true);
                        newactor.SetTexture(GraphicManager.textureman.get(texture));
                    }
                }
                else if (filename.EndsWith(".x") || filename.EndsWith(".X"))
                {
                    if (texture.Equals(""))
                    {
                        newactor.LoadXFile(Core.basepath + filename, true, true);
                    }
                    else
                    {
                        newactor.LoadXFile(Core.basepath + filename, false, true);
                        newactor.SetTexture(GraphicManager.textureman.get(texture));
                    }
                }
                _TVactor_namelist.Add(filename, 1);
            }
            else
            {
                //this kind of mesh is already loaded, we duplicate it
                TVActor original = Core.Global.GetActor(filename);
                newactor = original.Duplicate();
                if (!texture.Equals(""))
                {
                    newactor.SetTexture(GraphicManager.textureman.get(texture));
                }
                _TVactor_namelist[filename] = _TVactor_namelist[filename] + 1;
            }

My actors always have only 1 texture on them.
The problem is:
when I load the one I change the texture, the first actor loaded appears black after I loaded the second one that use the same mesh with a different texture.

You can check yourself in this screen:


One of my teammate think the problem should be a decrementation bug on the original texture I loaded at the first time.

Quote
The woman in black is the first one, the others are created by duplication of the mesh and texture loading. The problem is TV3D seems to have a bug when we duplicate mesh, it doesn't increase the texture ref count. However, when we do a setTexture, it thinks about updating ref counts (decrease of the old texture ref count, increase of the new one).
So, at each duplication+texture loading combo on the new mesh, the ref count of the original texture is deacreased and after reaching 0 is deleted by the textureManager at the next update.
« Last Edit: August 18, 2009, 03:33:21 AM by akd » Logged
akd
Customers
Community Member
*****
Posts: 53


WWW
« Reply #1 on: August 18, 2009, 03:31:41 AM »

Small add-on to previous post.

I manage the loading and unloading of texture via a TextureManager class.

The unload of textures is done by the following piece of code:

Code:
[...]
public static TVTextureFactory Tex;
[...]
 public void update()
{
 IEnumerator i = _texture_list.GetEnumerator();
 List<String> toDelete = new List<String>();
 //Retrieval of the elements that needs to be deleted
 while (i.MoveNext())
 {
  if (Tex.GetTextureRefCount(Core.Global.GetTex((String)i.Current))< 0)
  {
    //the texture is unused, we will add it to the deletion list
    toDelete.Add((String)i.Current);
    }
  }
  //Deletion of elements
  i = toDelete.GetEnumerator();
  while (i.MoveNext())
  {
    Tex.DeleteTexture(Core.Global.GetTex((String)i.Current));
    _texture_list.Remove((String)i.Current);
   }
}



The value returned by Tex.GetTextureRefCount(Core.Global.GetTex((String)i.Current)) is incorrect so I'm deleting the texture that is said to be unused but is used in fact.
Logged
akd
Customers
Community Member
*****
Posts: 53


WWW
« Reply #2 on: September 04, 2009, 02:38:23 AM »

Hi everyone,

I sort of corrected my bug by redoing all the texture count managing by using a get and a release function on my texture manager.

This is a pain in the ass just because as I said sooner and nobody responded, the internal counter of TV3D is BUGGED for real. With my own counter, I don't delete the texture too early and my mesh get its colors back.

I use a lot of different texture in my game; I can't let textures uploaded in the graphical memory all the time because I'm at the limit of the graphic memory capacity of my graphic card.

Is there any chance my report can be taken in count one day or the counter will stay bugged forever?

Thanks by advance.
Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4946


WWW
« Reply #3 on: September 04, 2009, 06:25:31 AM »

Well of course it would be better to fix it in the engine. I will check the actor duplication code to see if I have forgot an AddReference. Is it the only place it happens?

Sorry for the delay!
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
akd
Customers
Community Member
*****
Posts: 53


WWW
« Reply #4 on: September 04, 2009, 07:00:48 AM »

At first glance it seems so but I can't guarantee, because for now I only used texture replacment in actors.

Anyway I'm glad to see in fine I found a way to be clear enough about the bug to see it taken in count.

(good luck with debug and thanks a lot).
Logged
SylvainTV
Administrator
Community Member
*****
Posts: 4946


WWW
« Reply #5 on: September 04, 2009, 02:45:51 PM »

Thanks, I fixed the texref problem for Actor.duplicate at least ! It was indeed totally missing !
Logged

Regards

Sylvain Dupont
TrueVision3D Developer
sylvain@truevision3d.com

TV3D IRC at http://chat.truevision3d.com or on server irc.truevision3d.com #Truevision3D. Come talk with us !
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks