@DigiNick
Congratulations on fatherhood! Get used to coding with one hand and rocking with the other.
Your current woes sound like a mystery problem I encountered - it is actually the most frustrating thing I dealt with as a Corona/Solar programmer . It was a memory leak involving transitions and timers in complicated multi-object life and death simulations. I’m assuming there is object “death” in your app as I see guys walking around with swords
OK, basically it goes like this: You have a bunch of “living” things interacting with transitions and timers. These living things can die and leave their transitions and timers without references to control them. This happens especially in scenarios where lots of things are interacting and lots of things can kill you. You might set up everything logically and programmatically correct but the disconnect is that Solar2D is frame-based and your timers and transitions are time-based.
Possible solutions:
-
As mentioned above, you can reduce the transition and timer load by using a single enterFrame to control multiple objects. I use one enterFrame to control movement for thousands of objects (non-physics).
-
Make sure you tightly control the death sequences of your objects - especially make sure they can’t die more than once. The final death collision could trigger multiple transitions and you would never know.
-
If you are pausing and restarting many transitions or timers - it can lead to some of the symptoms you’ve described.
-
If you use conventions like
object.transition = transition.to( )
that can be problematic when the object dies
-
This is time-consuming but it was the ultimate solution for me. Add every transition and timer to a table so you can track them and cancel them manually when the object is killed, just to make sure they are deleted. You can then also delete expired and cancelled transitions and timers.
*If this sounds promising, I can give you more details. In the meantime, I would need to see the code you use to call timers and transitions.
So Nick, a lot of people show up on the forums and ask for help but aren’t willing to put in the work. You have shown us that you are willing to put in the work and that’s why we are all cheering you on. We’ve all been on the precipice where you find yourself now - thoroughly frustrated, feeling defeated and wondering if we can really do this. The answer for you is “yes you can”. If you have the desire and commitment you can make this happen - you’ve shown the fortitude to make it this far. Will it be easy, no, it will be taxing and frustrating and utterly deflating but you will emerge on the other side as a stronger more confident programmer. @roaminggamer helped me out a ton when I was first starting and I like returning that energy to the community now - someday it might be you giving back.
Personally, I’ve been heartbroken to throw away a project I had put many hundreds of hours into and start it over from scratch but then I realized that the first project was really just a sketch. As an artist, I might do a ton of sketches before I tackle a larger project and I’ve found that mindset helpful in programming.
In business there is a theory called “sunk cost” where people tend to overvalue the things they’ve already invested time or money in - it’s one of the reasons people stay in bad relationships. That’s the theory that led me to start fresh with the project I mentioned above and I’m glad I did. Whether or not you do decide to restart this project or future projects, know that it is always a valid option.
Enjoy your new journey into fatherhood and we’ll be here to help with your journey into programming whenever you are ready
– Jonathan (sporkfin)