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

Author Topic: (Solved) Problem with Tutorial: window.draw() causes exception  (Read 5202 times)

0 Members and 2 Guests are viewing this topic.

GCshepard

  • Newbie
  • *
  • Posts: 2
    • View Profile
(Solved) Problem with Tutorial: window.draw() causes exception
« on: December 18, 2014, 05:31:13 am »
I'm having an incredibly novice issue while following the tutorial for Visual Studio with SFML (http://www.sfml-dev.org/tutorials/2.2/start-vc.php). I have almost everything working with the sample code provided by the tutorial to test that I set up the project and linking fine:
#include "stdafx.h"
#include "SFML/Graphics.hpp"

int main(int argc, _TCHAR* argv[])
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);

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

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

        return 0;
}
However, when I try to run the code, I get the following error:
Quote
Unhandled exception at 0x0000000000000000 in HelloWorld.exe: 0xC0000005: Access violation executing location 0x0000000000000000.
I've had a bit of experience in the distant past with the C# binding of SFML, and remembered that x64 and x86 can't mix (which was also pretty visible around on the internet), and had fixed that before I tried running the program, so it seems like that isn't the issue here. (I am running the x64 version, though I honestly don't need to be)

What I did find is that when I comment out the following line/code:
window.draw(shape);
the program stops crashing, and shows the SFML window. No matter what I do to what's being drawn on the screen, I can't seem to make the error stop appearing without simply not drawing anything (which unfortunately doesn't help much).

For reference/full disclosure, here are .lib I linked into the project:
Quote
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;sfml-system-s-d.lib;winmm.lib;openal32.lib;sndfile.lib;sfml-window-s-d.lib;opengl32.lib;winmm.lib;gdi32.lib;sfml-graphics-s-d.lib;freetype.lib;glew.lib;jpeg.lib;opengl32.lib;
More Details: I'm statically linking, and have taken the extra step needed that I understood from the tutorial (add the SFML_STATIC; to one of the project properties). I've also checked that I am in-fact running in debug mode. I did remove the sfml-audio-s-d.lib to make sure that wasn't somehow the issue, though I did leave its dependencies in the linker list.

EDIT: Quick Summary: window.draw(shape); is mysteriously, single-handedly crashing the tutorial code from (http://www.sfml-dev.org/tutorials/2.2/start-vc.php) into an unhandled exception. It most definitely is a novice mistake. I will gladly accept any suggestions/help.

I've done a good amount of searching online for the issue, but I haven't been able to find a solution in any of the posts. For the moment, I'm completely out of ideas on things to double-check. If you have any suggestions or things for me to try, I'd greatly appreciate it.
-Gab C
« Last Edit: December 19, 2014, 05:29:34 am by GCshepard »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Problem with Tutorial: window.draw() causes exception
« Reply #1 on: December 18, 2014, 10:04:16 am »
I'm definitely not good enough at build errors to spot exactly what the issue is here, but I can't help noticing that your code is NOT the same as the tutorial's code, because you have Windows-specific junk like stdafx.h and _TCHAR* in there.  Maybe that has something to do with it.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
AW: Problem with Tutorial: window.draw() causes exception
« Reply #2 on: December 18, 2014, 12:29:27 pm »
Are you in release mode? Don't mix debug libraries (-d suffix) and the release mode.

Also: Only add SFML's dependencies once, i.e. there should only be one winmm.lib.
« Last Edit: December 18, 2014, 12:31:10 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

GCshepard

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: AW: Problem with Tutorial: window.draw() causes exception
« Reply #3 on: December 18, 2014, 08:59:04 pm »
I'm definitely not good enough at build errors to spot exactly what the issue is here, but I can't help noticing that your code is NOT the same as the tutorial's code, because you have Windows-specific junk like stdafx.h and _TCHAR* in there.  Maybe that has something to do with it.
Right, it is almost exactly the tutorial's code, since I built it in 2013 and it came with those parts. I had tried removing the stdafx.h, but it returned an error. I just now tried completely removing the input args part of the main, but unfortunately that didn't fix anything, and stdafx.h still returns an error. I also tried creating a new project that does not include the extra stdafx.h junk, but that returns the same unhandled exception error.

Are you in release mode? Don't mix debug libraries (-d suffix) and the release mode.

Also: Only add SFML's dependencies once, i.e. there should only be one winmm.lib.
I am most definitely in debug mode; I made sure about that multiple times. I fixed the repetition of .lib includes, and even tried running the project in release mode after tweaking the include .lib, but unfortunately the unhandled exception error still gets thrown.

Thank you both for the suggestions, though!

EDIT: Out of curiosity and a grab into the dark, I'm going to download the 32-bit version of SFML and build the project with that. I'll update the project and try it with that once the download decides to work. It might actually fix the issue, since I remember having a problem with x64/x86 in the past when I did the C# binding of SFML, since I consistently missed some obscure option somewhere in the config properties. I'll update here when I have results. EDIT2: Unfortunately, that didn't fix anything, either. However, when I run it in 32-bit mode, the error changes to the following:
Quote
Unhandled exception at 0x77D81A91 in HelloSimple.exe: 0xC0000005: Access violation executing location 0x00000000.
Not sure how useful that new piece of information is, but it's something new, at least. Unfortunately, googling that hexcode returns absolutely nothing of significance (only two results appear, and they both have to do with FlightSim).


EDIT: Apparently, even though it's been a full reset since I had updated the drivers on this computer, the graphics drivers hadn't been fully installed (which meant OpenGL wasn't updated). After a second reset, which prompted a windows update, the project builds and runs like a charm. (I had moved to a new computer to visit family over winter break, so the computer I'm using is a fresh install). *sigh*
« Last Edit: December 19, 2014, 05:48:59 am by GCshepard »