I just installed the newest version of CodeBlocks (13.12 with TDM-GCC-4.8.1) and now my code doesn't work. In the older version that I had, everything compiled and ran flawlessly, but now, using the same code, it compiles but crashes at run-time saying that my program "has stopped working", and returns -1073741510 (0xC0000005).
I ran into this with a more complicated program I have been working on, so I tried just running the example give from SFML to try and isolate the issue and that breaks the exact same way, so it seems to be something to do with SFML, but I don't understand what or why.
This is the code:
#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;
}
This is the call stack:
#0 691C4AF9 sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int) () (D:\MyDocs\DOCUME~1\C__~1\SFML2~1.0TE\SFML2T~1\bin\Debug\sfml-window-2.dll:??)
#1 00401424 main() (D:\MyDocs\Documents\C++\SFML 2.0 Test\SFML 2 Test\main.cpp:5)
Does anyone have any idea why this is happening or how I can fix it?
SFML is a C++ library, thus every time you switch the compiler, you need to recompile the library. The pre-compiled binaries provided by SFML are for the older version of TDM and thus not compatible with TDM 4.8.1. Building libraries yourself will become more important the longer you develop, so the sooner you start the better, plus it's not that hard.
As a personal side note: While I appreciate the hard work by TDragon, it's quite a no-go that the TDM compilers change the default linking behavior of GCC, thus breaking about every build script in existance, unless it's specially modified for TDM. Unfortunately the Code::Blocks community doesn't care at all. Thus I feel the need to point people to MinGW Builds whenever possible.
Related
I am learning how to link SFML so I can use the window tools. My ultimate goal is to write some sort of Chess or Asteroid game just to practice getting better at programming. I used the SFML tutorial to get all of my linking straightened out, and I am doing it dynamically with the .dll files. Everything in this code compiles on Visual Studio 2017, but when the console comes up the error I get is , "The application was unable to start correctly (0xc000007b)."
I am assuming this is some sort of memory error? It took me a while to learn the linking and now I am stuck. Thanks for any help!
PS. This is just suppose to be a simple display a window with a green circle inside of it.
#include "pch.h"
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <time.h>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(200,200), "My First Window");
CircleShape shape(100.f);
shape.setFillColor(Color::Green);
while (window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type == Event::Closed)
{
window.close();
}
window.clear();
window.draw(shape);
window.display();
}
}
return EXIT_SUCCESS;
}
The answer is already mentioned in the comments, but I will put an actual answer here so it's more visible.
The error code 0xc000007b means that the required .dll files are not in located in PATH or the local directory. To fix this issue, either place your required .dlls in a directory in the system PATH, or in the executable directory.
Also, you need to make sure that you do not mix 32 bit and 64 bit libraries, they are incompatible with each other.
Thank you drescherjm.
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.
I'm using SFML 2.1 (SJLJ) for Windows / GCC (32bit) and am building the project in CodeBlocks 10.05.
I'm trying to run the following code and it crashes. It builds smoothly however.
#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;
}
Many may recognize that this is taken directly from the SFML 2.1 tutorial site so I doubt there is anything wrong with the code. I've followed all instructions carefully but I have no clue what's causing it.
Some screenshots showing the build options and the actual error output are provided below:
I had no idea what was wrong specifically but upgrading to CodeBlocks 13.12 fixed the issue for me. It compiles perfectly now!
Using Code::Blocks, W7, Ati Card
I have this silly problem, I tried to compile a sample program from SFML website - http://www.sfml-dev.org/tutorials/2.0/start-cb.php
Everything set correctly, I think. When I start (Build and run) It throws out a crash, when looking into crash details it points out window-2-d.
All the .dll files are in the project directory, obviously a dynamic build.
RC from the website, for version 2.0 (I couldn't use 1.6 anyway because of ATI bug)
Tried to use this code to run it
#include <iostream>
#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;
}
Help?
If you're using the latest Code::Blocks version, which includes GCC 4.7.1, then you have to recompile SFML on your own (or use my Nightly Builds), because the ones provided are only for GCC versions < 4.7.x.
I couldn't use 1.6 anyway because of ATI bug
SFML 2 is better anyways, so don't worry.
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.