game dev help

Pages: 12
Hello all,

I recently upgraded my compilier to visual studio 2013 express and have been having trouble ever since.

I am trying to use sfml but when I compile my test code I get a nasty error. I have to close out of my compilier completely to escape it.

Here is the error:

Unhandled exception at 0x5B8B4A40 (sfml-graphics-2.dll) in demo.exe: 0xC0000005:
Access violation writing location 0x00000003.

I am not sue what this means, nor what to do about it.

The problem happens from one line of code. If I comment out this line the code works fine, but I need this line.

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
using namespace std;
#include <SFML/Graphics.hpp>
#include "demo.h"


int main() {

	cout << "hi";
	cin.get();
	
	sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
	sf::RenderWindow window(sf::VideoMode(800,600, desktop.bitsPerPixel), "Demo"); // ,sf::Style::None);
	window.setVerticalSyncEnabled(true);
	
	sf::Font font; //declare a font.
	if (!font.loadFromFile("sansation.ttf")) {
		return 17;
	}
	
	// Initialize the pause message
	sf::Text myText; //declare a text.
	myText.setFont(font);
	myText.setCharacterSize(20);
	myText.setPosition(50.f, 40.f); //(left x, top y)
	myText.setColor(sf::Color::Green);
	//myText.setString("Just some text."); <-----------Problem is here!!!!
	
	int gameLevel = 0;

	while (window.isOpen()) {
		
		sf::Event events;
		while(window.pollEvent(events)) {
		if (events.type == sf::Event::Closed) {
		window.close();
		}
		if (events.type == sf::Event::KeyPressed) {
		//cout << events.key.code;
		if(events.key.code == 36) { //the escape key.
		window.close();
		}
		}
		}

		if (gameLevel == 0) {
			//titlePage(window, myText);
		}

		
	}// while window.isOpen


	return 0;
}


Thanks for any help.
You should check the sfml forum, anyway this error usually means that you are yousing wrong library files, sometimes the debug in release or the release in debug. Pleas check this and the forum.
That's a super interesting error!

This:
Access violation writing location 0x00000003.


Means a program was trying to write data to the memory at byte three. Are you following a tutorial? Because I don't see any glaringly obvious holes right off the bat. Have you checked to see if myText actually points to something (you can just cout << &myText; to output the pointer value, or you can use a debugger)

You could be linking to the release dlls (ie no-d in the dll name) and trying to build against the debug library files, or the other way around.
Last edited on
When I run in debug mode I get this error:


Run-Time Check Failure #2 - Stack around variable 'myText' was corrupted.
@ OP: Did you remember to recompile the SFML library from source using your new version of MSVS? There is no downloadable for 2013 from SFML's website so you have to do this by hand.
You are right computergeek I forgot to update my sfml. I was using the download for my previous 2010. Do you know how to recompile by hand? I don't.
Just use CMake. Run CMake against the 'CMakeLists.txt' file, then go make a sandwich while it builds.
Is there anyone who has built sfml for visual studio 2013 express and could walk me through the steps, starting with exactly what to download and so on? Sorry for being such a baby, thanks. :)
I'm installing MSVS 2013 now OP. I usually use cl through Code::Blocks so it will take me a minute to get acquainted with the new UI.
Cmake seems to generate wrong project files for visual studio.
if sfml can't be done on vs2013 then my next question would be which ide compilier would be most recommended?
I'd say GCC\MingW, but that's more of a personal preference then a functional one. You'll want something that is up to date so Clang might be another choice to look into.
I will look into them.
@Manga
You certainly can use SFML with VS2013. IIRC the latest version of cmake generates correct VS2013 project files, if not you can generate 2012 files, when you open the solution in 2013 it should convert them.
you've done this? did it work?
It has been a while since I set it up with VS2013, but I'm pretty sure this is what I followed.

http://en.sfml-dev.org/forums/index.php?topic=13010.0
Manga wrote:
you've done this? did it work?
Yes i have. But you shouldn't have to covert the solution. I just generated VS2013 files using the latest cmake (3.0) and it generated correct files that built without issue. What version of cmake are you using?
To be honest, I have never used CMake before so I must learn it first. But I was not sure if it was even possible but thanks for letting me know it can be done. When you use sfml with vs2013 do you get any trouble with the sf::Text? I read this is a common problem.
This is only a common problem because what you did is a common mistake. This kind of error suggests that a stack corruption is the underlying issue. So when people on forms read it they understandably expect the error to be present in the users code just like the other posters in this thread did. Would you like to know how you can tell? Look at how many hits you get when you Google this error, then tell me how many of those issues are resolved or even not abandoned all together. If it were an issue with the framework then that would be reliably replicated. The SFML developers would then run a stack trace and resolve it with a hot patch, they are not amateurs after all.
okay so to get started on this, lets say I got vs2013 already installed. Next I should download the sfml source code. then download Cmake 3.0...

then what do I do?
Pages: 12