So, I've decided to start off at SFML, but whenever My program gets closed, a memory acces violation occurs, either by window::Close() or return.
Here's my code, which is actually part of one of their tutorials.
[cpp]#include "stdafx.h"
#include <SFML/Graphics.hpp>
int main(int argc, char** argv)
{
sf::WindowSettings Settings;
Settings.DepthBits = 24; // Request a 24 bits depth buffer
Settings.StencilBits = 8; // Request a 8 bits stencil buffer
Settings.AntialiasingLevel = 8; // Request 8 levels of antialiasing
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Test", sf::Style::Close, Settings);
//App.PreserveOpenGLStates(true);
//sf::String FPS("fps", sf::Font::GetDefaultFont(), 30.f);
sf::String FPS;
FPS.SetText("fps");
FPS.SetFont(sf::Font::GetDefaultFont());
FPS.SetSize(10.f);
FPS.SetColor(sf::Color::White);
while (App.IsOpened())
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
App.Close();
if (Event.Type == sf::Event::KeyPressed)
{
if (Event.Key.Code == sf::Key::Escape)
App.Close();
}
}
float ElapsedTime = App.GetFrameTime();
App.Clear();
App.Draw(FPS);
App.Display();
}
return EXIT_SUCCESS;
}[/cpp]
I ask you, facepunch, because I cba to create a new account at their forums right now.
But yes, I've searched.
If it helps, I'm using C++ in MSVC '09.
/I believe it's because you are doing clear-draw-display and stuff after you are closing, Move that stuff before your event testing and see what happens.
Only thing I can think of :o
Declare the font on the heap (as it's fairly large), because once I had a std::vector<sf::Image> (also fairly large), and I got the same error upon closing, changing to std::vector<sf::Image*> fixed things.
[editline]09:49PM[/editline]
Oh you're using the default SFML font.
Well don't, try to declare your own font, on the heap of course.
@Tezza: Unfortunately, it didn't help, same error.
@Sporbie: If I try to declare my own font, then it will report that it cannot open the ttf file.. Do I have to copy it over to the program's directory? Shouldn't it pull it out of the system fonts?
EDIT: How would one declare the font on the heap?
[editline]09:32PM[/editline]
Actually, nevermind that last edit.
I still get the same error, though.
This is what it's point to:
[cpp]void WindowImplWin32::SetActive(bool Active) const
{
if (Active)
{
if (myDeviceContext && myGLContext && (wglGetCurrentContext() != myGLContext))
wglMakeCurrent(myDeviceContext, myGLContext);
}
else
{
if (wglGetCurrentContext() == myGLContext)
wglMakeCurrent(NULL, NULL);
}
}[/cpp]
In the file WindowImplWin32.cpp
Got back from other stuff.
Anyway, this error only occurs with text, and I read somewhere that it has to do with it's deconstructor, being called twice or something.
If it's the error I'm thinking of, it's because of the default font. Linking statically should get rid of the error.
It's the default font, try using your own.
I've tried doing
[cpp]sf::Font MyFont = new sf::Font;
if (!MyFont.LoadFromFile("C:\\WINDOWS\\Fonts\\arial.ttf", 30))
return EXIT_FAILURE;
//---
FPS.SetFont(MyFont);[/cpp]
But to no avail.
try
[cpp]
sf::Font * MyFont = new sf::Font;
if (!MyFont->LoadFromFile("C:/WINDOWS/Fonts/arial.ttf", 30))
return EXIT_FAILURE;
//---
FPS.SetFont(&MyFont);
[/cpp]
And remember to specify the font in the sf::String's constructor, otherwise it will load the default font first.
[QUOTE=BMCHa;16844493]
[b]And remember to specify the font in the sf::String's constructor, otherwise it will load the default font [/b]first.[/QUOTE]
[i]I did not try this before[/i]
That solved it, thank you, no more access errors :D
Sorry, you need to Log In to post a reply to this thread.