1
General / My window crashes the instant i compile the code and execute it.
« on: October 17, 2015, 09:45:08 pm »
As soon as i debug and run the code it crashes on instant and i dont know why. Could someone help me!
Main
mainMenu.cpp
mainMenu.h
Can someone help me solve this problem? ive been at it for 2/3 hours now and i think it might just be something really simple...
Main
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Audio/Music.hpp>
#include <iostream>
#include "mainMenu.h"
int main()
{
sf::RenderWindow window( sf::VideoMode( 600, 600 ), "RPG" );
mainMenu menu(window.getSize().x, window.getSize().y);
sf::Music menuMus;
if (!menuMus.openFromFile("battletheme.wav"))
std::cout<<"Sound file not found"<<std::endl;
//menuMus.setVolume(25);
//menuMus.setLoop(true);
// menuMus.play()
while ( window.isOpen( ) )
{
sf::Event event;
while ( window.pollEvent( event ) )
{
switch ( event.type )
{
case sf::Event::Closed:
window.close( );
break;
}
}
window.clear( );
menu.draw(window);
window.display( );
}
}
#include <SFML/Audio.hpp>
#include <SFML/Audio/Music.hpp>
#include <iostream>
#include "mainMenu.h"
int main()
{
sf::RenderWindow window( sf::VideoMode( 600, 600 ), "RPG" );
mainMenu menu(window.getSize().x, window.getSize().y);
sf::Music menuMus;
if (!menuMus.openFromFile("battletheme.wav"))
std::cout<<"Sound file not found"<<std::endl;
//menuMus.setVolume(25);
//menuMus.setLoop(true);
// menuMus.play()
while ( window.isOpen( ) )
{
sf::Event event;
while ( window.pollEvent( event ) )
{
switch ( event.type )
{
case sf::Event::Closed:
window.close( );
break;
}
}
window.clear( );
menu.draw(window);
window.display( );
}
}
mainMenu.cpp
#include "mainMenu.h"
mainMenu::mainMenu(float width, float height)
{
if(!font.loadFromFile("arial.ttf"))
{
//handle error
}
menu[0].setFont(font);
menu[0].setColor(sf::Color::Red);
menu[0].setString("Play");
menu[0].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *1));
menu[1].setFont(font);
menu[1].setColor(sf::Color::White);
menu[1].setString("Options");
menu[1].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *1));
menu[2].setFont(font);
menu[2].setColor(sf::Color::White);
menu[2].setString("Exit");
menu[2].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *3));
}
;
void mainMenu::draw(sf::RenderWindow &window){
for(int i=0; 1< MAX_NUMBER_OF_ITEMS; i++)
{
window.draw(menu[i]);
}
}
mainMenu::mainMenu(float width, float height)
{
if(!font.loadFromFile("arial.ttf"))
{
//handle error
}
menu[0].setFont(font);
menu[0].setColor(sf::Color::Red);
menu[0].setString("Play");
menu[0].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *1));
menu[1].setFont(font);
menu[1].setColor(sf::Color::White);
menu[1].setString("Options");
menu[1].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *1));
menu[2].setFont(font);
menu[2].setColor(sf::Color::White);
menu[2].setString("Exit");
menu[2].setPosition(sf::Vector2f(width/2, height/(MAX_NUMBER_OF_ITEMS + 1) *3));
}
;
void mainMenu::draw(sf::RenderWindow &window){
for(int i=0; 1< MAX_NUMBER_OF_ITEMS; i++)
{
window.draw(menu[i]);
}
}
mainMenu.h
#ifndef MAINMENU_H
#define MAINMENU_H
#include "SFML/Graphics.hpp"
#include "SFML/Audio.hpp"
#define MAX_NUMBER_OF_ITEMS 3
#pragma once
class mainMenu
{
public:
mainMenu(float width, float height);
mainMenu();
void draw(sf::RenderWindow &window);
void MoveUp();
void MoveDown();
private:
int selectedItemIndex;
sf::Font font;
sf::Text menu[MAX_NUMBER_OF_ITEMS];
};
#endif // MAINMENU_H
#define MAINMENU_H
#include "SFML/Graphics.hpp"
#include "SFML/Audio.hpp"
#define MAX_NUMBER_OF_ITEMS 3
#pragma once
class mainMenu
{
public:
mainMenu(float width, float height);
mainMenu();
void draw(sf::RenderWindow &window);
void MoveUp();
void MoveDown();
private:
int selectedItemIndex;
sf::Font font;
sf::Text menu[MAX_NUMBER_OF_ITEMS];
};
#endif // MAINMENU_H
Can someone help me solve this problem? ive been at it for 2/3 hours now and i think it might just be something really simple...