Videotexture image can't be stored in custom class variable?

Does anyone know why I can’t store a videotexture image object in a custom class variable?

I can store a videotexture image in an object property or in bge.logic but when try to store it in a variable of a custom class the object texture doesn’t change.

Here is a example (you must unpack it)
dynamic texture.zip (88.2 KB)

Here is the important part of the code where you can switch between the 3 ways to store the image via comment/uncomment


         [...]

        """
        # Doesn't work
        self.texture = bge.texture.Texture(self.ob, mat_id)        
        self.texture.source = bge.texture.ImageBuff()
        self.texture.source.load(image_buffer, self.size[0], self.size[1])
        
        self.texture.refresh(False)
        """
        
        """
        # Work 
        logic.texture = bge.texture.Texture(self.ob, mat_id)        
        logic.texture.source = bge.texture.ImageBuff()
        logic.texture.source.load(image_buffer, self.size[0], self.size[1])
        
        logic.texture.refresh(False)
        """
        
        #"""
        # Work too
        self.ob['texture'] = bge.texture.Texture(self.ob, mat_id)        
        self.ob['texture'].source = bge.texture.ImageBuff()
        self.ob['texture'].source.load(image_buffer, self.size[0], self.size[1])
        
        self.ob['texture'].refresh(False)
        #"""

First thing that comes to my mind is that “self” is not the same self. I say that because in your code the statements that work all involve a wider scope:
logic.texture doesn’t change when self changes and self.ob[‘texture’] seems to set an external memory location that “self” might well correctly get in the initialization.
To tell you if this hypothesis stand I should see the init function and its usages though.

Update: ok, i was wrong. I see zero reasons why your code shouldn’t work.

@pgi The full code is in the example file but I have found my mistake. Thank you anyway for the time that you have spent with my problem.

I’m sorry, it is very simple:

I have forgotten to store the reference of my class instance, so the instance and the videotexture image are deleted in the next frame because there are no references anymore. But bge.logic and object properties work because they are still exist in the bge also when my classobject doesn’t exist anymore.

Cool. It can be a pain keeping track of where your classes are stored.
I sometimes appended mine to a list twice and ended up running update() twice every frame. Or forgot to update them at all…

It’s something that’s worth keeping track of, so it’s best to have a standard method of storing different objects as part of your project architecture. My own project has a line in the base class to automatically append themselves to the right list in a central location once they are called and initialize correctly. This is inherited by all the subclasses, so I can always find all my agents, sound effects, particles etc… in the right location.