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

Author Topic: [SOLVED] Access violation reading location  (Read 44918 times)

0 Members and 1 Guest are viewing this topic.

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
[SOLVED] Access violation reading location
« on: May 08, 2013, 06:09:22 pm »
So, im pretty new to C++ and SFML and i ran into an error with this code:
#include "stdafx.h"
#include <SFML/Graphics.hpp>

int main()
{
    // create the window
    sf::RenderWindow window(sf::VideoMode(800, 600), "2D Sprites");
        sf::Texture texture;
        sf::Sprite sprite;

        sprite.setTexture(texture);
        sprite.setPosition(sf::Vector2f(50, 50));

        texture.loadFromFile("TAA1TAA.png");
        texture.setSmooth(true);


    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        window.draw(sprite);

        // end the current frame
        window.display();
    }

    return 0;
}
and the error (or exception):
First-chance exception at 0x6E9ADCF8 (msvcr110.dll) in Test2.exe: 0xC0000005: Access violation reading location 0x00277000.

As im new to SFML and C++, im not really sure how this error came, but it seems to come from the Graphics module for sure. Opening Windows gives me no such errors.
« Last Edit: May 10, 2013, 07:26:24 pm by taa1taa »

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Access violation reading location
« Reply #1 on: May 08, 2013, 07:11:02 pm »
I believe you are linking to debug libraries in release mode. I may be wrong tho.

Also, you want to set the sprite's texture after it is loaded, not before. I think otherwise you won't see anything.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Access violation reading location
« Reply #2 on: May 08, 2013, 07:14:02 pm »
Hey,

first you should always create an empty project with Visual Studios. You dont need the stdafx.h.

Try to load the texture first and then call *.setTexture(); . But i´m not sure if this is causing your problem.



Edit: Grimshaw was faster...xD


AlexAUT



taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #3 on: May 08, 2013, 08:11:32 pm »
Thanks for the replies, but none of them worked D: i made a new empty project, fixed the sprite and texture thing, now they are in the right order, but it still opens up the console and the window, starts spamming completely random stuff into the console and then after 2-4 seconds it gives me an exception error.
Some more Information:

OS: Windows 7 Professional 64bit
IDE: Visual Studio Express 2012

I Have been browsing around this and other forums, and i havent yet found anyone with the same problem as I have, well, some others have Access violation reading location too, but the code is more like 1000 lines then :/ i have only *i dont know how many* lines.. (probably less than 50)

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Access violation reading location
« Reply #4 on: May 08, 2013, 09:33:24 pm »
*Did you used the Debugger?
*Are you sure that you have linked the right libs? (Debug/Release)?

Because this code should run without an error.


AlexAUT
« Last Edit: May 09, 2013, 09:21:11 am by AlexAUT »

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #5 on: May 09, 2013, 01:08:50 pm »
Yes, im running it with Debugger all the time and i have linked the debugger libs

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Access violation reading location
« Reply #6 on: May 09, 2013, 03:41:08 pm »
Maybe the *.png is corrupt? Did you tried a other image?

Wich SFML version do you use? Pre-compiled or did you compile SFML by your own?


AlexAUT

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #7 on: May 09, 2013, 03:55:11 pm »
Not really sure whats the difference between Pre-compiled and getting on your own, but i downloaded the SFML 2.0 Visual Studio 2012 pack and added the additional library and include directories and additional depencies on my own, yeah. Another thing what i was worried about, is that my computer is 64bit but only the 32bit pack works for me, the 64bit SFML gives me a fatal error.

Raphman

  • Newbie
  • *
  • Posts: 40
    • View Profile
    • Email
Re: Access violation reading location
« Reply #8 on: May 09, 2013, 04:18:15 pm »
32 vs 64 bits is dependant on what your compiler is, not your OS.

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #9 on: May 09, 2013, 04:37:42 pm »
I guess Visual Studio 2012 is always 32bit :P

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #10 on: May 09, 2013, 09:27:39 pm »
So.. no one has no idea WTF is the error/exception im having? :O

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Access violation reading location
« Reply #11 on: May 09, 2013, 10:15:03 pm »
Quote
So.. no one has no idea WTF is the error/exception im having?
The debugger probably knows that. Where does it crash? What's the call stack?
Laurent Gomila - SFML developer

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #12 on: May 10, 2013, 03:37:51 pm »
Quote
So.. no one has no idea WTF is the error/exception im having?
The debugger probably knows that. Where does it crash? What's the call stack?
heres the call stack:
    ntdll.dll!778115de()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
>   msvcp110.dll!std::basic_streambuf<char,std::char_traits<char> >::sputn(const char * _Ptr, __int64 _Count) Line 203   C++
    sfml-graphics-2.dll!5399137c()   Unknown
    sfml-graphics-2.dll!5399a041()   Unknown
    msvcr110.dll!_unlock(int locknum) Line 366   C
    msvcr110.dll!_unlockexit() Line 801   C
    msvcr110.dll!__dllonexit(int (void) * func, void (void) * * * pbegin, void (void) * * * pend) Line 272   C
    0038f354()   Unknown

Grimshaw

  • Hero Member
  • *****
  • Posts: 631
  • Nephilim SDK
    • View Profile
Re: Access violation reading location
« Reply #13 on: May 10, 2013, 06:43:30 pm »
You re totally linking release libraries in debug mode.. Unless I am very wrong, that explains why you don't have more clear debug information! :)

taa1taa

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Access violation reading location
« Reply #14 on: May 10, 2013, 07:21:43 pm »
ill try some stuff...
EDIT: Thanks Everyone! It Worked! I Really like how everyone helps here, when im good at SFML Ill come here helping too for sure :D
« Last Edit: May 10, 2013, 07:25:45 pm by taa1taa »

 

anything