SFML community forums

Help => Graphics => Topic started by: Nihu on April 20, 2015, 03:21:23 pm

Title: Drawing text - Unhandled exception
Post by: Nihu on April 20, 2015, 03:21:23 pm
Hello,

I have problem with drawing both text and sprites.
I can draw shapes without problems but when trying to draw text I'm getting following:

Quote
Unhandled exception at 0x74FCCB49 in SFML learning.exe: 0xC0000005: Access violation executing location 0x00000000.

and from the debug output
(click to show/hide)

I'm using VS2013, the correct version of .dll(debug ones). The code is from tutorials/example code in API doc.
I have no clue what is wrong and knowing life there will be easy fix but I just don't see it So I need your help  ;)

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

sf::Font font;
if (!font.loadFromFile("arial.ttf"))
return EXIT_FAILURE;


sf::Text text("Hello SFML", font, 50);

while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}

window.clear();
window.draw(text);
window.display();
}

return 0;
}
}
Title: AW: Drawing text - Unhandled exception
Post by: eXpl0it3r on April 20, 2015, 03:52:18 pm
Where did you get the SFML binaries from?
Title: Re: Drawing text - Unhandled exception
Post by: Nihu on April 20, 2015, 04:00:35 pm
From the site: http://www.sfml-dev.org/download/sfml/2.2/
Visual C++ 12 (2013) - 32-bit
Title: AW: Drawing text - Unhandled exception
Post by: eXpl0it3r on April 20, 2015, 04:08:01 pm
Is your GPU driver up to date?
Title: Re: Drawing text - Unhandled exception
Post by: Nihu on April 20, 2015, 05:58:23 pm
I've tested my "project" on another pc and it works there.

My GPU driver is up to date but as far I remember I had some problems with it on this notebook and never pinpointed what exactly is wrong. It never bothered me since I don't use it for anything else beside college stuff. Guess I will have to use the other PC.

Thanks anyway  ;)
Title: Re: Drawing text - Unhandled exception
Post by: eXpl0it3r on April 20, 2015, 06:11:26 pm
If it works on other PCs and it's not the GPU driver, it's most likely a bad RAM. Run memtest86 or similar over night and you should know for sure.
Title: Re: Drawing text - Unhandled exception
Post by: binary1248 on April 20, 2015, 06:13:37 pm
You know... a bit more information also wouldn't harm. You haven't even mentioned what GPU you are using let alone what driver version is actually installed. Many people claim that their driver is "up to date" but until I see numbers, I can't believe them, especially with laptops. Also, do you have a laptop with multiple GPUs? They go by the brand names Optimus and Enduro or PowerXpress.

If nobody bothers fixing stuff that is broken, things will never get better...
Title: Re: Drawing text - Unhandled exception
Post by: zsbzsb on April 20, 2015, 06:15:34 pm
To me it looks like there isn't a GPU driver installed, try the code from the following post and tell us the output.

Quote from: http://en.sfml-dev.org/forums/index.php?topic=17245.msg128946#msg128946
To tell for sure whether that is really the case, after you create your sf::Window or sf::RenderWindow, use window.getSettings() to get the settings of the created context and check the OpenGL version, like this:
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::ContextSettings settings = window.getSettings();
std::cout << "Major: " << settings.majorVersion << " Minor: " << settings.minorVersion << std::endl;
In addition to that you can check the vendor and renderer strings that OpenGL returns:
#include <SFML/OpenGL.hpp>

std::string vendor = reinterpret_cast<const char*>(glGetString(GL_VENDOR));
std::string renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER));
std::cout << "Vendor: " << vendor << " Renderer: " << renderer << std::endl;
This was also what I said just a few days ago here (http://en.sfml-dev.org/forums/index.php?topic=17914.msg128829#msg128829), and mentioned a few weeks ago here (http://en.sfml-dev.org/forums/index.php?topic=17793.0).
Title: Re: Drawing text - Unhandled exception
Post by: Nihu on April 20, 2015, 07:41:21 pm
GPU - NVIDIA GeForce 310M
driver: newest one,  341.44

Zsbzsb code returns:
Major: 1 Minor: 1
Vendor: Microsoft Corporation
Render: GDI Generic

Which shows that somehow I don't have the correct drivers but

OpenGL Extension Viewer shows
Renderer: GeForce 310M/PCIe/SSE2
Vendor: NVIDIA Corporation

and rendering test run on 3.3 in this program works properly


EDIT: If I put the zsbzsb code after the mainloop(after closing the window) instead after RenderWindow it returns:
Major: 2 Minor: 0
Vendor: GeForce 310M/PCIe/SSE2
Render: NVIDIA Corporation

Also RenderWindow returns "Failed to share the OpenGL context" - I probably should have mentioned that earlier
Title: Re: Drawing text - Unhandled exception
Post by: Jesper Juhl on April 20, 2015, 07:47:36 pm
Zsbzsb code returns:
Major: 1 Minor: 1
Vendor: Microsoft Corporation
Render: GDI Generic
So, for some reason you are using the default Windows OpenGL drivers that cannot provide the minimum required OpenGL v 1.2 context.
Is the laptop perhaps using "Optimus graphics" which switches between build-in gpu and external gpu? If that's the case have you tried forcing it to always use the nvidia gpu?
Others probably have better guesses - Windows is not my strongest side.
Title: Re: Drawing text - Unhandled exception
Post by: Nihu on April 20, 2015, 07:53:18 pm
It's Lenovo z560 laptop and it doesn't have the optimus technology.
Title: Re: Drawing text - Unhandled exception
Post by: binary1248 on April 20, 2015, 08:42:26 pm
Yeah... I think I know why it's broken, and I'm quite sure it should have been fixed since the pixel format fix that got merged a week ago. The pixel format that was being selected was probably not hardware accelerated because SFML didn't get to pick the best from multiple possible formats in the old (2.2) codebase.

At this point I would have provided an archive for you to test, but SFML's CI doesn't produce them at the moment. :P

Can you build the latest master revision from GitHub yourself and see if the problem still exists?
Title: Re: Drawing text - Unhandled exception
Post by: eXpl0it3r on April 20, 2015, 09:17:02 pm
SFML master for VS 2013 (32 bit) (http://my-gate.net/pub/SFML-master.zip)
Title: Re: Drawing text - Unhandled exception
Post by: Nihu on April 20, 2015, 09:50:51 pm
Yay, it works  :)

Thanks for the help.
Title: Re: Drawing text - Unhandled exception
Post by: binary1248 on April 21, 2015, 04:12:10 am
Can you show us the output of zsbzsb's code with the new version? I want to see if it really solved the pixel format selection problem. The fact that it no longer crashes when using software OpenGL was an unrelated fix.
Title: Re: Drawing text - Unhandled exception
Post by: Nihu on April 21, 2015, 05:01:00 pm
Major: 3 Minor: 3
Vendor: NVIDIA Corporation
Renderer: GeForce 310M/PCIe/SSE2