My plan was to put all my created GameObjects, PlayerObject, BallObject, BrickObject in my <GameObject*> vector.
I think I coded for 8 hours non stop, changing bascilly all code to a more dynamic way.
I must have been delusional because i went way ahead of my skill level and falled short when it came to accessing all derived Objects from said vector. I read up on Internet sources and I thought I had found a way.
Something like this (taken from Stackoverflow):
(edit: you can see the text below if you select the area with your mouse, don't know why it turned white)
std::vector<A*> aVector;
aVector.push_back(new B());
B* b = (B*)aVector[0];
cout << b->j;
(http://stackoverflow.com/questions/13569661/c-reach-derived-class-variables-from-vector)where A is the parent class and B is the derived /inherited class.
B* b = (B*)aVector[0];
This line was my salvation. or so I thought. Instead it almost became my doom.I got all sorts of crashes. I just didn't get it to work after alot of trying I gave up. Luckily I had made 2 backups.
When I went back to the backup and opened up the project to my FEAR it was the same project I just closed!! I checked and double checked and triple checked! I opened the second backup as well and it was also the same! I started sweating.....OMG!!! ALL IS LOST!!! all work the last few weeks. GONE!
It just couldn't be!....how could it? I made the backups way before the major changes. Why did all projects look the same! I think I spent an hour just panicing. But being a programmer and all I started to break down the problem and decided to open each cpp file one by one in notepad next to Visual studio so I could check the code line by line. Thank god I did! I shortly realized that when you copy a whole Visual Studio project/solution and it got the same name as the original folder it somehow opens the most recent file even if they are in different folders on your computer. It was so strange.
I created a new project with a different name and copied all the cpp and heather files to the new project. The joy to see my original code. I could breathe again. I was saved!
Tip: If you want to backup your project. just copy your cpp and .h files and all art and stuff. Do NOT copy the whole solution/project.
I spent the rest of the day repairing and improving the backup I salvaged.
This whole mess made me grow in understanding alot. why some crashes happen and how to code in a better way. Sure I didn't get much done compared to last time but I learned alot and I'm happy for this little incident.
(Sorry for bad English and writing. no spellchecking tonight. I'm too tired)
No comments:
Post a Comment