Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Drawing text - Unhandled exception  (Read 7770 times)

0 Members and 1 Guest are viewing this topic.

Nihu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Drawing text - Unhandled exception
« 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;
}
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Drawing text - Unhandled exception
« Reply #1 on: April 20, 2015, 03:52:18 pm »
Where did you get the SFML binaries from?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nihu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing text - Unhandled exception
« Reply #2 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Drawing text - Unhandled exception
« Reply #3 on: April 20, 2015, 04:08:01 pm »
Is your GPU driver up to date?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nihu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing text - Unhandled exception
« Reply #4 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  ;)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Drawing text - Unhandled exception
« Reply #5 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Drawing text - Unhandled exception
« Reply #6 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...
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Drawing text - Unhandled exception
« Reply #7 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.

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, and mentioned a few weeks ago here.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Nihu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing text - Unhandled exception
« Reply #8 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
« Last Edit: April 20, 2015, 08:22:59 pm by Nihu »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Drawing text - Unhandled exception
« Reply #9 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.

Nihu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing text - Unhandled exception
« Reply #10 on: April 20, 2015, 07:53:18 pm »
It's Lenovo z560 laptop and it doesn't have the optimus technology.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Drawing text - Unhandled exception
« Reply #11 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?
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Drawing text - Unhandled exception
« Reply #12 on: April 20, 2015, 09:17:02 pm »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nihu

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Drawing text - Unhandled exception
« Reply #13 on: April 20, 2015, 09:50:51 pm »
Yay, it works  :)

Thanks for the help.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Drawing text - Unhandled exception
« Reply #14 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.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).