SFML - Access violation reading location when saving RenderTexture to image 0xC0000005

1

I'm using Visual Studio 2017. When debugging it points me to line 11

texture.getTexture().copyToImage().saveToFile("C:/test.bmp");

with an error

Exception thrown at 0x54B06B9E (sfml-graphics-2.dll) in Project2.exe: 0xC0000005: Access violation reading location 0xCCE6C37F.

I want to save the texture to a .bmp file.

#include<iostream>
#include<SFML/Graphics.hpp>

int main()
{
    using namespace sf;
    RenderTexture texture;
    texture.create(800, 600);
    texture.display();
    texture.clear(Color::Black);
    texture.getTexture().copyToImage().saveToFile("C:/test.bmp");

    return 0;
}

EDIT

As far as we've detected it's the .saveToFile("C:/test.bmp") fragment that's causing the issue, the code works fine without it

SECOND EDIT

I got SFML packages manually, I include them from a set folder each time I'm making a new project and link the libraries, also added manually through external lib folder

THIRD EDIT

After some work I managed to fix the debug libraries and release libraries, now the code throws an exception

Run-Time Check Failure #2 - Stack around the variable 'texture' was corrupted.

A screenshot with the whole output and code: enter image description here

Another thing is, when I continue without handling the exception it throws at me this:

Unhandled exception at 0x00D26859 in Project2.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.

c++
opengl
sfml
access-violation
asked on Stack Overflow Jan 23, 2019 by Yee7i • edited Jan 29, 2019 by alseether

2 Answers

1

My best guess is that you're linking the libraries somehow wrong. Ensure you have debug libraries in debug configuration and release ones in release configuration.

Remember, debug libraries usually end with a "d". If you don't set debug libraries correctly, you cannot debug your code and that would explain why you're getting a poor error message.

I leave here a link to SFML forum with someone with a similar issue.

Hope that helps.


As side note, for beginners with I highly recommend install the library using NuGet packages (right click on your solution -> Manage NuGet packages -> look for SFML -> install)

This works for SFML, not sure for OpenGL.

answered on Stack Overflow Jan 25, 2019 by alseether
0

I found an answer, the issue was that I wasn't using .dlls compiled for VS 2017, I was using those compiled for 2015 instead, switched them and it works like a charm

answered on Stack Overflow Feb 18, 2019 by Yee7i

User contributions licensed under CC BY-SA 3.0