Unhandled exception at 0x5401FA96 (sfml-system-d-2.dll) - c++

I am trying to make a simple program with SFML. The source code is the same provided in this example
Given that I downloaded SFML from the site using the precompiled version from Visual Studio 12.
I configured the project normally, and added the correct libraries for debug and release.
Note:
There were no compiler errors, and not linker errors as well. I also added the .dll libraries in the .exe directory.
When I run the program, here is the output (just crashes):
Exception thrown at 0x50FAFA96 (sfml-system-d-2.dll) in TestSFML.exe: 0xC0000005: Access violation reading location 0xCCCCCCD8.
If there is a handler for this exception, the program may be safely continued.
From what I looked on the internet, this error seems to be related to mixing debug and release libraries, but I think I did it right.
Note that I am using Visual Studio Community 2015, but I don't think this could cause the problem.
The configuration inside the project
Release and Debug (All Configurations):
Added the same directory for the include path (release and debug) and library path (release and debug).
Release
On Linker -> Input I added:
sfml-window.lib
sfml-system.lib
Debug
On Linker->Input I added:
sfml-system-d.lib
sfml-window-d.lib
Since I am using dynamic libraries, I also added the libraries on the directory of the executable.
EDIT
Main.cpp
#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>
int main()
{
// create the window
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
// load resources, initialize the OpenGL states, ...
// run the main loop
bool running = true;
while (running)
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, event.size.width, event.size.height);
}
}
// clear the buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw...
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
return 0;
}
Aditional dependencies on the project. They were set on Active(Debug)
opengl32.lib
sfml-system-d.lib
sfml-window-d.lib
The compilation
1>------ Build started: Project: TestSFML, Configuration: Debug x64 ------
1> main.cpp
1> TestSFML.vcxproj -> C:\Users\Leonardo\documents\visual studio 2015\Projects\TestSFML\x64\Debug\TestSFML.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

I got the same error when trying to compile a SFML program with SFML for VS2013 when using VS2015. Downloading (and obviously using) the correct version solved the problem.

Related

How to work on one SFML-C++ Project with different Visual Studio versions?

I'm working on a C++ project that requires SFML (free portable library) and some dependencies which I can copy onto a usb-stick/drive.
The issue is that I'm working with Visual Studio 2019 at home and very often at uni/work with Visual Studio 2013.
Whenever I try to run the project from one version on the other, exceptions and other errors are thrown around.
The only fix is creating a new project and annoyingly add each dependency & lib folder which I would absolutely 100% positively avoid at all cost...
How can I, aside from making two sepearte projects for each VS version, work on one project with different versions of Visual Studio?
I've tried using a portable codeblocks 17.02 copy but the IDE is not very pleasant to work with, especially since I own a Visual Studio Key and other students will review the code in Visual Studio as well.
This is just some simple window creation example:
#include <SFML\Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow Window;
Window.create(VideoMode(800, 800), "VS2013-VS2019Example");
while (Window.isOpen()) {
Event e;
while (Window.pollEvent(e)) {
if (e.type == Event::Closed) {
Window.close();
}
}
Window.clear();
Window.display();
}
}
I expected the program to create a new window, 800x800 with a title and no interception.
Starting the program will result in VS indicating that line 8, the line where window.create() is called, throws a Access violation reading location 0x000FFF exception at 0x0F15A5E3 (msvcp120.dll) in [project name].exe.

SFML 2.1 and Codeblocks Error: sfml-graphics-2.dll is missing from your computer

I've just begun to use c++ and SFML, and everything FINALLY ran fine. Before I would get Undefined Reference Errors, but I realized that I had been downloading the wrong type of SFML, getting SJLJ instead of DW2. The problem was fixed, but was replaced with another; now whenever I run an SFML program, it opens a small windows:
It says:
The program can't start because sfml-graphics-2.dll is missing from
your computer. Try reinstalling the program to fix this problem.
And then when you press "Ok" or closed the window, the program would stop working. NOT TO BE CONFUSED: the program never opened, on the console did.
Here is the Code (probably useless) directly copied and pasted from the codeblocks tutorial site:
#include <SFML/Graphics.hpp>
int main()
{
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;
}
Copy all dll files from main SFML > bin directory and paste them into your project folder. In my case it is C:\Users\myname\Documents\Visual Studio 2017\SFML\SFML
and if you want to run just the exe file. Place all dll files the same directory as the main exe file.
SFML is dynamically linked by default, which means that you need to place sfml-graphics-2.dll (along with the dll files of any other SFML subsystems you use) inside the same directory as your executable.
Best option is Copy All the .dll files from SFML-2.4.2 > bin. And past them to C: > Windows > System32 folder. That's all you need to do.
Then Run your Program.
you will be able to run it.
I had a similar problem. My error was when I was linking the libraries in the Compiler setting I had forgot to add the suffix "-s-d". This ending allows the compiler and debugger to function properly.

error running a code with libstdc++6.dll

I was trying to compile and run the following code on my CODE::BLOCKS sftwr but
It could never run properly due to some problems with a dll "libstdc++6.dll"
I leave you the code listing and the error log in debug mode (f8)
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv){
ALLEGRO_DISPLAY *display = NULL;
if(!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if(!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0,0,0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
Debug output:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: c:\telechar\Codeblocks\Mesprojets\MonProjet\
Adding source dir: c:\telechar\Codeblocks\Mesprojets\MonProjet\
Adding file: c:\telechar\Codeblocks\Mesprojets\MonProjet\bin\Debug\MonProjet.exe
Changing directory to: c:/telechar/Codeblocks/Mesprojets/MonProjet/.
Set variable: PATH=.;C:\Telechar\CodeBlocks\MinGW\bin;C:\Telechar\CodeBlocks\MinGW;
C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;c:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Windows Live\Shared
Starting debugger: C:\Telechar\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet -args c:/telechar/Codeblocks/Mesprojets/MonProjet/bin/Debug/MonProjet.exe
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.5
Child process PID: 5536
Error while reading shared library symbols for c:\telechar\Codeblocks\Mesprojets\MonProjet\libstdc++-6.dll:
...
Error while reading shared library symbols for c:\telechar\Codeblocks\Mesprojets\MonProjet\libstdc++-6.dll:
Program received signal SIGSEGV, Segmentation fault.
In al_destroy_display () (c:\telechar\Codeblocks\Mesprojets\MonProjet\allegro-5.0.10-md.dll)
Continuing...
Program received signal SIGSEGV, Segmentation fault.
In al_destroy_display () (c:\telechar\Codeblocks\Mesprojets\MonProjet\allegro-5.0.10-md.dll)
Continuing...
[Inferior 1 (process 5536) exited with code 030000000005]
Debugger finished with status 0
the weird thing is that in release mode, it seems to work fine (a window appears for a while then closes itself, in debug mode, the screen displays but it has a blue color instead, at the end, it does crashes)
Following the comments of the question, I guess the problem comes from the fact that you use MinGW 4.7.1, provided with CodeBlocks, whereas your Allegro binaries are compiled for MinGW 4.7.0.
According to this similar question which point to this forum thread, the version of the compiler used for Allegro and for your program must be the same. Thus, you can either:
Download a version of Allegro compiled for MinGW 4.7.1,
or compile Allegro by yourself, using MinGW 4.7.1,
or use MinGW 4.7.0 instead of the version provided with CodeBlocks.

LINK : fatal error LNK1561: entry point must be defined ERROR IN VC++

I installed MS VS VC++ for the first time in order to start programming OpenGL with GLFW library. I follower instructions on how to install it over at http://shawndeprey.blogspot.com/2012/02/setting-up-glfw-in-visual-studio-2010.html
Then I wrote this simple program, just to test it, which did work on Eclipse:
#include <stdlib.h>
#include <GL/glfw.h>
using namespace std;
int main()
{
int running = GL_TRUE;
if (!glfwInit()) {
exit(EXIT_FAILURE);
}
if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
glfwTerminate();
exit(EXIT_FAILURE);
}
while (running) {
// glClear( GL_COLOR_BUFFER_BIT );
glfwSwapBuffers();
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
}
glfwTerminate();
exit(EXIT_SUCCESS);
return 0;
}
But then I got this awful error:
------ Build started: Project: first1, Configuration: Debug Win32 ------
LINK : fatal error LNK1561: entry point must be defined
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I know, I've looked around on the internet and the only solution I found was "It requires main() function in order to work". I obviously have it, right there, but it still throws me the same fatal error :(
Would be great to get response on how to fix it. There might me a flaw in the installation process or something.
Is this a console program project or a Windows project? I'm asking because for a Win32 and similar project, the entry point is WinMain().
Right-click the Project (not the Solution) on the left side.
Then click Properties -> Configuration Properties -> Linker -> System
If it says Subsystem Windows your entry point should be WinMain(), i.e.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
your code here ...
}
Besides, speaking of the comments. This is a compile (or more precisely a Link) error, not a run-time error. When you start to debug, the compiler needs to make a complete program (not just to compile your module) and that is when the error occurs.
It does not even get to the point being loaded and run.
In my case, the program was running fine, but after one day, I just ran into this problem without doing anything...
The solution was to manually add 'Main' as the Entry Point (before editing, the area was empty):
It cant find the entry point for your program, in this case main(). Your linker settings are likely incorrect.
See this post here
change it to Console (/SUBSYSTEM:CONSOLE) it will work
You can get this error if you define a project as an .exe but intent to create a .lib or a .dll
I've had this happen on VS after I changed the file's line endings. Changing them back to Windows CR LF fixed the issue.
In Visual Studio:
Properties -> Advanced -> Entry Point -> write just the name of the function you want the program to begin running from, case sensitive, without any brackets and command line arguments.
Main was missing in the entry point configuration.

Using SFML with Visual Studio 2010

Right now I'm trying to get SFML to work with my Visual Studio 2010, so I can start learning how to make windows applications and games using the libraries within SFML. I'm following the tutorial here to open a new window, but my program seems to break instantly. I really don't know why :S. It seems to build and compile, but then breaks:
Edit: It breaks at this line: App.Create(sf::VideoMode(800, 600, 32), "SFML Window");
#include <SFML/Window.hpp>
int main ()
{
sf::Window App;
App.Create(sf::VideoMode(800, 600, 32), "SFML Window");
bool Running = true;
while (Running)
{
sf::Event Event;
while (App.GetEvent(Event))
{
if (Event.Type == sf::Event::Closed)
Running = false;
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
Running = false;
}
App.Display();
}
return EXIT_SUCCESS;
}
Also, I should note:
On the SFML website, the tutorials for setting it up with Visual Studio seem to be for VS 2008 (Setting up SFML with VS). I managed to get a set of instructions for VS2010 and set it up. I used a short program to test if the SFML libraries were working:
#include <SFML/System.hpp>
#include <iostream>
int main()
{
sf::Clock Clock;
while (Clock.GetElapsedTime() < 5.f)
{
std::cout << Clock.GetElapsedTime() << std::endl;
sf::Sleep(0.5f);
}
return 0;
}
^ This program worked fine.
The SFML libraries are compiled for Visual Studio 2008. If you use it with VS2010, it will 'kind of' work. You'll get messages about a corrupted stack, and possibly other hard crashes when you call certain functions (like App.Clear()).
You need to either recompile the source code for the libraries yourself, or find a version where somebody else has done that. I don't believe there's an 'official' source, but if you search the forums at the SFML site, you'll find some links to libs compiled for 2010.
Late answer, I know... but this question is still coming all the time.
I'm pretty sure the error you are getting here is because you used Window instead of RenderWindow.