I have created a game in c++ using sfml. It is still in early stages. I have an error I can not figure out. It compiles perfectly but when it is run, it instantly crashes. It happened after I added the area I commented as inventory
and the area commented as item_use. Please n[ote I had to cut out some functions.
struct map
{
int block[MAPWIDTH+1][MAPHEIGHT+1];
int entity[(MAPWIDTH+1)*16][(MAPHEIGHT+1)*16];
bool colition[MAPWIDTH*16][MAPHEIGHT*16];
}map;
struct entity
{
std::string name[ENTITY_NUMBER+1];
int health[ENTITY_NUMBER+1];
int algohrithm[ENTITY_NUMBER+1];
std::string image[ENTITY_NUMBER+1];
int number;
}entity;
struct block
{
std::string name[BLOCK_NUMBER+1];
int physics[BLOCK_NUMBER+1];
std::string image[BLOCK_NUMBER+1];
int number;
}block;
struct inventory
{
int selectx;
int selectz;
int inventory[INVENTORY_WIDTH][INVENTORY_HEIGHT];
}inventory;
struct item
{
std::string name[ITEM_NUMBER];
std::string image[ITEM_NUMBER];
std::string image2[ITEM_NUMBER];
int flags[ITEM_NUMBER];
bool useable[ITEM_NUMBER];
int flags2[ITEM_NUMBER];
int number;
int entity[ITEM_NUMBER];
}item;
/////////////////////////////////////////////////////////Expeirimental/////////////////////
//class mesh
//{
//public:
//bool main[16][16];
//bool get_mesh(int x,int y);
//void change_mesh(int x, int y, bool change);
//};
//class MESHARRAY
//{
//public:
//void clear_array(int array, bool clear);
//bool main[MESH_ARRAY_NUMBER][16][16];
//bool get_mesh(int array, int x,int y);
//void change_mesh(int array, int x, int y, bool change);
//};
//MESHARRAY block_mesh;
//MESHARRAY entity_mesh;
//bool MESHARRAY::get_mesh(int array ,int x, int y)
//{
//return main[array][x][y];
//}
//void MESHARRAY::change_mesh(int array, int x, int y, bool change)
//{
//main[array][x][y]=change;
//}
/////////////////////////////////////////////Player Functions/Structs/////////////////////////////
struct player
{
int x;
int y;
int id;
int speed;
int block_location_x;
int block_location_y;
int face;
bool mesh[16][16];
}player;
////////////////////////////////////////////Global Variables/////////////////////////
//MESHARRAY playermesh;
int mouse_x;
int mouse_y;
/////////////////////////////////////////////main//////////////////////////////////////
I am looking for graphics help myself yet a technique that works really well for me is to comment out recent code and try to run it. If it still doesn't run just keep commenting back and then take a look at the commented code and tweak it until it works again. That always works for me.
You cannot have global variables of types sf::Texture or sf::RenderWindow. It is recommended that you have no global variables of any type defined in the sf namespace.
Why? SFML depends on its global variables being constructed before yours and there is no way to guarantee that happens in standard C++ when multiple translation units are involved.