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

Author Topic: segfault while saving to png  (Read 6932 times)

0 Members and 1 Guest are viewing this topic.

timesqueezer

  • Newbie
  • *
  • Posts: 3
    • View Profile
segfault while saving to png
« on: November 07, 2010, 02:51:20 am »
It seems that stbi_zlib_compress causes this segfault while saving an image as png. When I use jpg it works fine.

Here's the gdb trace:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff79601cf in stbi_zlib_compress(unsigned char*, int, int*, int) ()
   from /usr/lib/libsfml2-graphics.so
(gdb) bt
#0  0x00007ffff79601cf in stbi_zlib_compress(unsigned char*, int, int*, int) ()
   from /usr/lib/libsfml2-graphics.so
#1  0x00007ffff79612f9 in stbi_write_png_to_mem(unsigned char*, int, int, int, int, int*) ()
   from /usr/lib/libsfml2-graphics.so
#2  0x00007ffff7961592 in stbi_write_png () from /usr/lib/libsfml2-graphics.so
#3  0x00007ffff7961c4b in sf::priv::ImageLoader::SaveImageToFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<unsigned char, std::allocator<unsigned char> > const&, unsigned int, unsigned int) () from /usr/lib/libsfml2-graphics.so

I'm working on a 64bit Arch Linux Laptop but it fails also on other systems.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
segfault while saving to png
« Reply #1 on: November 07, 2010, 10:23:32 am »
Quote
it fails also on other systems

All 64 bits?
Laurent Gomila - SFML developer

timesqueezer

  • Newbie
  • *
  • Posts: 3
    • View Profile
segfault while saving to png
« Reply #2 on: November 07, 2010, 01:55:02 pm »
Yes they're all 64bit.

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
segfault while saving to png
« Reply #3 on: November 07, 2010, 04:56:31 pm »
I can confirm this. I had actually posted this some time ago:
http://www.sfml-dev.org/forum/viewtopic.php?t=3390

Xorlium

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
segfault while saving to png
« Reply #4 on: November 07, 2010, 05:13:52 pm »
Confirming as well. Arch Linux x86_64 here.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
segfault while saving to png
« Reply #5 on: November 07, 2010, 05:43:16 pm »
I've sent an e-mail to the author of stb_image, hopefully he can do something about it.
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
segfault while saving to png
« Reply #6 on: November 07, 2010, 05:48:10 pm »
Laurent, can you replicate the problem at all?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
segfault while saving to png
« Reply #7 on: November 07, 2010, 05:59:50 pm »
I haven't tried yet.

Anyway, here is his answer:
Quote
For the crashes, I don't know for sure, but try -fno-strict-aliasing
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
segfault while saving to png
« Reply #8 on: November 08, 2010, 07:27:25 pm »
Doesn't work here. I recompiled my whole project with that setting but no dice.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
segfault while saving to png
« Reply #9 on: November 08, 2010, 08:08:09 pm »
I think SFML has to be recompiled with this option.
Laurent Gomila - SFML developer

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
segfault while saving to png
« Reply #10 on: November 08, 2010, 08:27:00 pm »
That worked indeed. Stupid me, of course, recompiling my project with that option effectively didn't do anything. So, what are we going to do? Make -fno-strict-aliasing a compile option for SFML2 or should this still be delegated to the image library?

EDIT: From a few quick searches it appears as using that options is undesirable. The issue should be fixed in the image library.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
segfault while saving to png
« Reply #11 on: November 08, 2010, 08:34:25 pm »
I agree. I'll see what the author can do.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
segfault while saving to png
« Reply #12 on: November 08, 2010, 11:23:57 pm »
I can apply -fno-strict-aliasing to stb_image only, which is fair enough. The author made the choice to stop fixing code related to strict aliasing (I can show his answer to people who are interested).

I updated the makefiles, can everybody test it again please? :)
Laurent Gomila - SFML developer

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
segfault while saving to png
« Reply #13 on: November 09, 2010, 07:56:56 am »
Works well for me now.

Thanks Laurent!

Xorlium

Silvah

  • Guest
segfault while saving to png
« Reply #14 on: November 09, 2010, 02:18:23 pm »
Quote from: "Laurent"
The author made the choice to stop fixing code related to strict aliasing (I can show his answer to people who are interested).
Sure, there's nothing wrong in depending upon undefined behavior, after all. I really wonder why he chose to leave the code broken.