im using
SFML 2.4 and Code::blocks as IDE and also glew+glm
i've followed Hopson's tutorial on how to make minecraft in c++ with sfml
and then on closing the window i get an error like "segmentation error"
code for display.cpp
#include "Display.h"
#include <memory>
#include <SFML/Graphics.hpp>
#include <GL/glew.h>
#include <iostream>
namespace Display
{
std::unique_ptr<sf::RenderWindow> window;
void init()
{
constexpr static int WIDTH = 800;
constexpr static int HEIGHT = 600;
sf::ContextSettings settings;
settings.depthBits = 24;
settings.majorVersion = 3;
settings.minorVersion = 3; // means OpenGL 3.3
window = std::make_unique<sf::RenderWindow>(sf::VideoMode(WIDTH, HEIGHT),
"OpenGL Window",
sf::Style::Close,
settings);
glewInit();
glViewport(0, 0, WIDTH, HEIGHT);
}
void close()
{
window->close();
}
void clear()
{
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
}
void update()
{
window->display();
}
void checkForClose()
{
//std::cout << "Checking for close.." << std::endl;
sf::Event e;
while(window->pollEvent(e))
{
if (e.type == sf::Event::Closed)
{
std::cout << "closing.." << std::endl;
close();
std::cout << "Successfully executed close();" << std::endl;
}
}
}
bool isOpen()
{
return window->isOpen();
}
}
and code for display.h
#ifndef DISPLAY_H_INCLUDED
#define DISPLAY_H_INCLUDED
namespace Display
{
void init();
void close();
void clear();
void update();
void checkForClose();
bool isOpen();
}
#endif // DISPLAY_H_INCLUDED