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

Author Topic: segfault when call draw  (Read 3932 times)

0 Members and 1 Guest are viewing this topic.

feare56

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
segfault when call draw
« on: December 30, 2014, 07:09:20 am »
When I try to test SFML 2.2 by using the example code in the tutorials. I have followed every step and when I try to run it I get "Segmentation fault (core dumped)". I have found that it is whenever I call the ".draw()" command, it would run without the segfault if I commented that line out. I am running Ubuntu 14.04 using Code::Blocks to write and run my code. I looked around the forum and there were similar issues where people had segfaults when using fonts using Linux and when they went to windows they had it working same code. Could it be Linux that is causing this, should I do switch back to windows?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
AW: segfault when call draw
« Reply #1 on: December 30, 2014, 09:07:50 am »
Did you build SFML yourself?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Biff

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: segfault when call draw
« Reply #2 on: December 30, 2014, 01:12:58 pm »
I wouldn't like to hijack the thread, but something similar - and I thought, possibly related - keeps happening to me - on Mac OS X 10.9.5, using SFML 2.2, and Xcode 6. I upgraded from 2.1. I first installed the binary, then built SFML from the source with CMake; in both cases, draw() calls crash with EXC_BAD_ACCESS (EXC_I386_GPFLT), when trying to run the examples / template project.

(Apologies if I'm overlooking something blindingly obvious.)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
Re: segfault when call draw
« Reply #3 on: December 30, 2014, 02:19:23 pm »
Biff: Create your own thread. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: segfault when call draw
« Reply #4 on: December 30, 2014, 05:20:06 pm »
Could it be Linux that is causing this, should I do switch back to windows?
This attitude really baffels me.
I see it time and time again on internet forums, mailing lists, when talking to younger coworkers, friends etc. This idea that "it must be my compiler, operating system, library, programming language etc that is causing my problem". Why is it that people don't realize that the most likely explanation for a problem is that they themselves did something wrong (especially since thousands of other people successfully use whatever they blame their issue on)? Is it really that hard for people to admit that a problem could be due to (even most likely) their own inexperience, lack of knowledge, oversight, screwup etc?

To answer your question: no, it is unlikely to be Linux that's causing your problem. It is most likely a bug in your own code or a failure (by you) to build/install/link/use SFML correctly in your environment.
You have a nice core dump, so why don't you pull out the debugger and investigate the actual root cause of the crash?
$ gdb app core   should do the trick.
« Last Edit: December 30, 2014, 05:43:06 pm by Jesper Juhl »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: segfault when call draw
« Reply #5 on: December 30, 2014, 10:45:53 pm »
Jesper, you forgot to mention the phase I love the most that some innocent people go through sometimes: my code doesn't work but it really should! I should format my computer and reinstall everything from scratch!  ::)
SFML / OS X developer

feare56

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: segfault when call draw
« Reply #6 on: December 31, 2014, 07:55:30 am »
I downloaded the Linux copy not the source, I just made sure everything was linked correctly in code::blocks an still same results. I did try to load a texture and try to display it, file loaded and I even tried changing the file to make it not detect the right file for the error message and it displayed the error, the problem there was still the ".draw(sprite);". Jesper, I have SFML 1.6 on my PowerMac g5 and the code from the tutorial works on that, except when I tried to follow a tutorial on loading tile maps using fstream (that is a bug with xcode 3.1 not allowing me to use fstream). I only asked if it was the operating system because as I stated when I was searching the forums for a thread with my problem someone had the same code on Linux and windows and windows worked and Linux had the segfault. I read somewhere that it may very well be Linux, not the operating system itself but their graphics driver isn't really the best as far as I read. Plus I know just enough Linux to get me by, I had to switch to Linux because my computer wasn't responding to a fresh install of windows 7. I tried getting the core dump, it worked but now I cant do it again, I will mess with it more tomorrow and post my core dump.

You guys also forgot something: my code won't compile! I have to buy a new computer and try again  ;D

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: segfault when call draw
« Reply #7 on: December 31, 2014, 04:51:49 pm »
In the case of C++ the only reason it won't let you use something is because you didn't include the library said something is within.
I have many ideas but need the help of others to find way to make use of them.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
AW: segfault when call draw
« Reply #8 on: December 31, 2014, 06:44:26 pm »
Download the source and build SFML with CMake on your own.

Also if get a segfault run it through gdb and provide the call stack.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

feare56

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: segfault when call draw
« Reply #9 on: December 31, 2014, 07:09:19 pm »
It was c++ but everything was linked. It compiled just fine it's just when it runs it gets the segfault. I will post the code dump later as I have to figure out why it was saying that it can't write a file to a read only filesystem, can't even move files to the desktop via the mv command in terminal

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: segfault when call draw
« Reply #10 on: January 01, 2015, 11:37:59 pm »
I downloaded the Linux copy not the source
Just for fun, could you try with a custom built SFML from source?

I just made sure everything was linked correctly in code::blocks an still same results.
Are you sure you don't have multiple copies of SFML installed?
Like, one from your distributions repositories + the one you downloaded? I'm thinking of issues where you use header files from one version but link against another or even at runtime the dynamic linker (ld.so) finds a third. Stuff like that can sometimes drive you crazy ;-)

I only asked if it was the operating system because as I stated when I was searching the forums for a thread with my problem someone had the same code on Linux and windows and windows worked and Linux had the segfault.
There can be a ton of reasons for that.
Your code may contain undefined behaviour that only causes a crash on some systems (but is of course a bug none-the-less).
I recommend reading these articles if you are not familiar with the concept of "undefined behaviour" (or even if you are; they are great reads regardless of your level of experience):
 What Every C Programmer Should Know About Undefined Behavior #1/3
 What Every C Programmer Should Know About Undefined Behavior #2/3
 What Every C Programmer Should Know About Undefined Behavior #3/3
 A Guide to Undefined Behavior in C and C++, Part 1
 A Guide to Undefined Behavior in C and C++, Part 2
 A Guide to Undefined Behavior in C and C++, Part 3

Your code may depend on implementation defined behaviour that then leads to different results when building with different compilers (example: I recently had to debug a problem that eventually turned out to be the code depending on the order of evaluation of function arguments (which is implementation defined) - Visual C++ and GCC evaluate from right to left and the code worked, clang evaluates from left to right and the code broke - both evaluation orders are perfectly fine, what was not fine was the code depending on it).

Your code may be just fine but run into resource limits on one system but not another.

You may not notice that the code "crashes" on one platform but may notice on another. Say for example that your Windows machine is not configured to generate minidumps on crashes but will just silently terminate the program while your Linux machine is configured to generate a core on crashes - so you'd notice more distinctly one one than the other.

Etc, etc etc.

I read somewhere that it may very well be Linux, not the operating system itself but their graphics driver isn't really the best as far as I read.
Driver quality varies a lot that's true. And sometimes the OpenGL drivers are responsible for app crashes; but I'd say it shouldn't be the first place to look for issues. When that's said though, NVidia tends to provide quite solid drivers in my experience and Intel's drivers are usually not bad either - AMD/ATI drivers are a bit more questionable (in my experience). If you are using Mesa and software rendering, that's a whole different kettle of fish, but the latest 10.x drivers seem to work reasonably well (although performance is of course nowhere near hardware accelerated levels).
In any case, upgrading to the latest stable drivers for your card is usually always a good idea.

I tried getting the core dump, it worked but now I cant do it again, I will mess with it more tomorrow and post my core dump.
Hint: ulimit -c unlimited
Don't bother posting your dump. It's useless without the executable that generated it. Just debug it locally (hint: learn to use gdb) or just re-run the app through the debugger - just run gdb app and then type "run" - it'll stop when it crashes and the "bt" command will get you a backtrace - google for gdb tutorials for more.

You guys also forgot something: my code won't compile! I have to buy a new computer and try again  ;D
Luckily, that one is rather uncommon.
« Last Edit: January 01, 2015, 11:55:58 pm by Jesper Juhl »

 

anything