Crash when using my own C++ objects

Hi, I created a simple example inline, i.e. created sprites and labels in the init() method of the Layer and manipulate with a schedule method. However, when I moved this logic to a custom class, e.g. Player, I passed in the layer and retained it, created the sprite in the init method, etc. In first view is works fine, however on first update in the schedule (0.2 seconds layer) the class has lost the retained reference to the layer. Is this a known problem?

I tried using the safe macro to retain and my own call to ->retain() on the layer object, it is definitely non-null. However in update method, the layer field, that I retained, it null. Still within the same layer as far as I know.

Thanks

Can you show how you are creating Player, Layer, and how you’re adding them into the scene? An instance is probably not added into the scene, or is not Ref* derived, or not retained, or released before update is called. Or your hierarchy of Layer/Player is not valid, or how you’re creating them is not. Hard to know without more precise explanation or some code.

1 Like

Show some code please so we can help

1 Like