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

Author Topic: access Violation Image::LoadFromFile()  (Read 2854 times)

0 Members and 1 Guest are viewing this topic.

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
access Violation Image::LoadFromFile()
« on: October 25, 2011, 02:03:39 pm »
Hello guys

I got an access Violation while loading an Image.
Here is the Error code:

Code: [Select]
Unbehandelte Ausnahme bei 0x10189024 (sfml-graphics-d.dll) in SFML Game.exe: 0xC0000005: Zugriffsverletzung beim Lesen an Position 0xcccccd00.

( In English: Unhandled Exception in Game.exe, Access Violation reading at position)


And here some of the source code (which isnt well designed atm =P)

Quote

void Game::InitBackground ()
{
   I_Background->LoadFromFile ("Graphic/background.tga");// here it chrashes
   
        // just some tests with random numbers
   S_Background->SetImage (*I_Background);
   S_Background->Resize (800, 600);
   S_Background->SetPosition (0.0, 0.0);
   S_Background->SetCenter (0.0, 0.0);
}


This should be the critical part as the debugger "told" me.

Additional the declaraton of class Game:

Code: [Select]

class Game
{
public:
Game (unsigned width, unsigned height, unsigned pixelformat);
~Game ();
void InitGame ();
void RenderProcedure ();


private:
void InitBackground ();

sf::RenderWindow* Window;
sf::Image* I_Background;
sf::Sprite* S_Background;
};



And Another question:
Which picture formats do SFMl support?
Cant find somethin about this in the documentation.

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
access Violation Image::LoadFromFile()
« Reply #1 on: October 25, 2011, 02:12:59 pm »
By the way, Libaries should be correctly linked.
The folder Graphic is in the same folder as the code datas.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
access Violation Image::LoadFromFile()
« Reply #2 on: October 25, 2011, 02:15:06 pm »
Your pointers are probably not initialized properly.

But you don't need pointers at all, anyway. Just get rid of them ;)

Quote
Which picture formats do SFMl support?

It's listed there:
http://www.sfml-dev.org/features.php
Laurent Gomila - SFML developer

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
access Violation Image::LoadFromFile()
« Reply #3 on: October 25, 2011, 03:00:41 pm »
Problems seems to be solved and thx for the list, I didnt think about it =P

However, now I have a new Problem.

After first creating, even before clearing, the window is closed immediatly.
(Probably just a stupid mistake by me =S)

Here the reworked sourece code of the memberfunctions of Game

Code: [Select]

#include "Game.hpp"

Game::Game ()
{
// do nothing atm
}

Game::~Game ()
{
// do nothing atm
}


void Game::InitGame ()
{
sf::RenderWindow (sf::VideoMode (800, 600, 32), "Game");

InitBackground ();
}


void Game::RenderProcedure ()
{
    while (Window.IsOpened () )
    {
        sf::Event Event;
        while (Window.GetEvent (Event) )
        {
            if (Event.Type == sf::Event::Closed)
                Window.Close ();
        }
        Window.Clear ();

Window.Draw (S_Background);

        Window.Display ();
    }
}


void Game::InitBackground ()
{
I_Background.LoadFromFile ("background.tga");

S_Background.SetImage (I_Background);
S_Background.Resize (800, 600);
S_Background.SetPosition (0.0, 0.0);
S_Background.SetCenter (0.0, 0.0);
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
access Violation Image::LoadFromFile()
« Reply #4 on: October 25, 2011, 03:11:40 pm »
Quote
Code: [Select]
sf::RenderWindow (sf::VideoMode (800, 600, 32), "Game")

You're calling the constructor of RenderWindow but without creating an instance of it. The consequence is that a new window is created and destroyed immediately. I think you want to call Window.Create(...) instead.
Laurent Gomila - SFML developer

Rexona for men

  • Newbie
  • *
  • Posts: 24
    • View Profile
access Violation Image::LoadFromFile()
« Reply #5 on: October 25, 2011, 03:41:02 pm »
Yeah thx =D

Now all is working fine