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

Author Topic: SFML 2.1 Bus error  (Read 2567 times)

0 Members and 2 Guests are viewing this topic.

TwoOfDiamonds

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
SFML 2.1 Bus error
« on: February 27, 2014, 04:57:48 pm »
I am using SFML 2.1 on Ubuntu 12.04 .
Anybody got this before ?



It seems like its from the SFML library rather than my game. Also the source code is from a SFML game dev book so it shouldn't have big bugs ... (though i didn't copy paste it)

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Re: SFML 2.1 Bus error
« Reply #1 on: February 27, 2014, 05:00:41 pm »
You're in the wrong section of the forum, it has nothing to do with SFML Website.

Do you have the last Book sources from GitHub ?

TwoOfDiamonds

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML 2.1 Bus error
« Reply #2 on: February 27, 2014, 06:14:35 pm »
Sorry for that . Didn't realise ... If anyone could move this topic to the correct section I'd be grateful.

It's not the source code from github exactly .. I just made the code how I saw in the book and only used the code from github to correct some stuff

Here is the code where the "magic" happens
template<typename Resource, typename Identifier>
template<typename Parameter>
void ResourceHolder<Resource, Identifier>::load(Identifier id, const std::string &filename, Parameter& secondParam)
{
  std::unique_ptr<Resource> resource(new Resource());
  if(!resource->loadFromFile(filename, secondParam))
    throw std::runtime_error("ResourceHolder::load couldn't load " + filename);
  auto inserted = mResourceMap.insert(std::make_pair(id, std::move(resource)));
  assert(inserted.second);
}
 

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 2.1 Bus error
« Reply #3 on: February 27, 2014, 08:04:42 pm »
It's not the source code from github exactly .. I just made the code how I saw in the book and only used the code from github to correct some stuff
We can't guess a bug in your custom code. Please read this post and try to come up with a minimal complete example.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TwoOfDiamonds

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML 2.1 Bus error
« Reply #4 on: February 27, 2014, 08:20:11 pm »
Ok . Here it is all the code I think it's needed

template <typename Resource, typename Identifier>
void ResourceHolder<Resource, Identifier>::load(Identifier id, const std::string &filename)
{
  std::unique_ptr<Resource> resource(new Resource());
  if(!resource->loadFromFile(filename)) //it breaks inside the loadFromFile function
  {
    throw std::runtime_error("ResourceHolder::load couldn't load " + filename);
  }

  auto inserted = mResourceMap.insert(std::make_pair(id, std::move(resource)));
  assert(inserted.second);
}
 

void World::loadTextures()
{

        std::cout << "world::loadtextures\n";
        mTextures.load(Textures::Eagle, "Media/Gfx/Eagle.png"); //the above function is called here
        std::cout << "eagle done\n";
        mTextures.load(Textures::Raptor, "Media/Gfx/Raptor.png");
        std::cout << "raptor done\n";
        mTextures.load(Textures::Desert, "Media/Gfx/Desert.png");
        std::cout << "desert done\n";
}
 

I made sure the files are there (even if they weren't it shouldn't give a bus error.


The World constructor
World::World(sf::RenderWindow& window)
: mWindow(window)
, mWorldView(window.getDefaultView())
, mTextures()  //constructor of mTextures here !!!
, mSceneGraph()
, mSceneLayers()
, mWorldBounds(0.f, 0.f, mWorldView.getSize().x, 2000.f)
, mSpawnPosition(mWorldView.getSize().x / 2.f, mWorldBounds.height - mWorldView.getSize().y / 2.f)
, mScrollSpeed(-50.f)
, mPlayerAircraft(nullptr)
{
        std::cout << "constr world::world\n";
        loadTextures();
        buildScene();

        mWorldView.setCenter(mSpawnPosition);
        std::cout << "exit world::world\n";
}
 

Also, the code compiles under g++ with c++0x standard.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 2.1 Bus error
« Reply #5 on: February 27, 2014, 08:37:33 pm »
Yes I know the code, I'm one of the authors ;)

But since we didn't have such a problem when we tested it, it's likely that you introduced a bug elsewhere or that something is wrong with your setup/environment. That's why I asked for the minimal example (read the link I posted). Does the problem appear if you simply load a texture in a main() function?

By the way, I recommend to have a look at the GitHub code from time to time, because some things have been improved since the release of the book.
« Last Edit: February 27, 2014, 08:39:11 pm by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TwoOfDiamonds

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML 2.1 Bus error
« Reply #6 on: February 27, 2014, 08:46:43 pm »
@Nexus ... OMG ... Thanks for this awesome book .
I'm trying to understand exactly what happens and debug as much as I can by myself thus improving my debugging skills and getting a better grasping of these concept.
It doesn't . Earlier when there was only the plane I had no problem. I know it's because of me ... but not sure why. I think it's something too subtle for my skills

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML 2.1 Bus error
« Reply #7 on: February 27, 2014, 08:54:44 pm »
A "bus error" may indicate an access to memory through an invalid pointer.

Locally there is the following dereferencing:
resource->loadFromFile(filename)
But since the unique pointer is initialized with a valid pointer one line above, that can't be the origin. It's rather undefined behavior, maybe you have a dangling pointer/reference, array out-of-bound access or something similar earlier in the program flow. Or maybe it's really a linking/configuration issue, so double-check this first. Otherwise, split the application into smaller parts, test things on their own and try to localize the issue.

But this kind of bugs is extremly tedious to find. You could also try with the GitHub code...
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

TwoOfDiamonds

  • Newbie
  • *
  • Posts: 8
    • View Profile
    • Email
Re: SFML 2.1 Bus error
« Reply #8 on: February 27, 2014, 09:47:26 pm »
Ok . Got the source code from github and I just modified the folders in order to keep the order how i wanted :D And it works ... I must have been doing something wrong . Thank you !

PS: Great job with the book.

 

anything