Hello SFML Community!
This question is a bit long, so I'll try to summarize it first as briefly as possible.
I'm having problem with my game project,
Blastorium.
It runs finely on my machine, but will
randomly stop working (went not responding) in other machines. I'm using Windows 7, but the errors show no consistency on OS or specs. The most likely cause is
heap corruption, as I did suffer from it some time ago (but it was solved on my machine).
My project's github can be found here, but as a disclaimer, I am an extreme beginner in C++ with nothing much of a guide on coding a program, so the code you're going to see is downright horribly untidy and unstructured.
Since I suspect scanning through all the files won't be feasible for most of you, here's the pseudocode:
Files used:
-Main.cpp (main)
-Interface.cpp (runs functions such as transition screens and main menu screen)
-Select.h/cpp (class, runs the select screen, that is, the part where you select weapons/stage)
-Tilelist and Texturemanager.h/cpp (class, manages sprites/textures and rendering individual sprites)
-Globals.h/cpp (class, contains a shared_ptr<> of all the classes below as for global access)
-Engine.h/cpp (class, the main game loop runs here. Calls most of other classes below)
-Player, Level, Powerups, WeaponManager, WpnBomb/Mine/Rocket/Medi .cpp/h (classes, maintains the aspects of the game such as players/powerups/etc, and also runs their Logic() and Render() functions every loop)
Each class below Engine.cpp has their own tilemanager and texturemanager, meaning they load files themselves and handles their own logic and rendering. Engine.cpp only calls them
Every class with the exception of main menu GUI classes (SelectManager) and utility classes (TileList, TileManager) is handled by GlobalManager class.
The GlobalManager class contains a shared_ptr<> to each of those classes, and each is initialized immediately once the app was run. Later on in the game. Engine.h will fill each of those classes with the necessary information based on user inputs (Which map, which weapons, etc). This is re-done every game loop, e.g. from start to game over.
Pseudocode of what's happening when you run it
- Run Main.cpp
- Main.cpp initializes Engine class, SelectManager class (select screen) and GlobalManager class
- Main.cpp calls MainMenu function (not a class) from Interface.cpp
- MainMenu() draws all the gears and receive input, returning an int
- If it signals a play command, main menu runs the SelectScreen function from SelectManager
- SelectScreen function receives input and returns accordingly
- Main.cpp runs the Go function of the Engine class, initiating the game
- Engine.cpp initializes every other class for a game round (levels, player, weapons, etc)
- Each respective classes loads their own files
- In each game loop, Engine calls the Logic and Render function of each class
- If a player's HP reaches zero, Engine calls the FinishMatch function of Data class
- Data class prints numbers then returns
- Engine then calls the EndGameChoice function (not from a class), which receives user input
- -If it selects play again, engine refreshes every class and runs again
-If it selects main menu, engine stops and the program returns to Main.cpp, to no.3 to be precise
-If it selects exit then the game exits accordingly
Heap corruptions commonly happens when you close the game (The last step, when you press exit) but in rare cases, during the initialization of the game after select screen (step no.7-9)
Do note that in previous versions, there were no select or main screens (meaning the program skips steps no. 3 to 6) and the game runs just fine. Perhaps that holds some relevance.
Anything that might help would be appreciated. As of now, I still hold very little knowledge on good/bad programming habits, or tracing the source of these errors, and programming in general.
I know that my coding is horrible and that the problem most likely stems from an incorrect structure of the program itself, but I really need help with it.. Most tutorials on the internet only covers the basics of a single file and not how they are supposed to work together, and I'm out of ideas on how to fix the problem (especially since it runs fine on my machine, making debugging difficult).
Another question, though not as pressing, is performance. Is there a reason why my game still somewhat lags at 30FPS even on machines that runs 3d games just fine? I'm pretty sure my code is not that horrible (or maybe it is) to cause such drop in performance
Thanks in advance, and sorry if the question is too much or lacking information.