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

Author Topic: [Partially Solved] Failing to compile with SJLJ SFML-2.0 binaries  (Read 4894 times)

0 Members and 2 Guests are viewing this topic.

Xaymar

  • Newbie
  • *
  • Posts: 10
  • No Sanctuary
    • View Profile
    • Shark Missile Interactive
Hey,

I've recently tried compiling my project with TDM-GCC and SFML-2.0 RC SJLJ, since TDM-GCC uses SJLJ. However, all I get is a Segmentation Fault, at Address 0000002B and Function ?? (). I've already tried recompiling the binaries with TDM-GCC and CMake and then clean->build, which doesn't change anything.
I managed to make it compile and run once, but I'm not sure how or what magic did that.

What else is there to try? Or rather, what am I doing wrong?

OS: Windows 7 64bit
GCC: TDM-GCC / MinGW SJLJ
GCC Version: 4.7.1
SFML: tag/tip (local repository updates every four hours)
Code:
/**
 * @file main.cpp
 * @author Shark Missile Interactive
 */


#include <SFML/System.hpp>

int main(uint32_t uiArgumentCount, char *cArgumentValue[]) {
        sf::Clock* oClockPtr = new sf::Clock(); //SIGSEGV

        return false;
}
 
Debugger Log:
Building to ensure sources are up-to-date
Selecting target:
Win32 Debug
Adding source dir: F:\Projekte\[C++] No Sanctuary\Game\
Adding source dir: F:\Projekte\[C++] No Sanctuary\Game\
Adding file: F:\Projekte\[C++] No Sanctuary\GameContent\NoSanctuary.x86.Debug.exe
Changing directory to: F:/Projekte/_C___N~1/GAMECO~1
Set variable: PATH=.;F:\Projekte\[C++] No Sanctuary\GameLibrary\SFML-2.0\lib;F:\Compiler\TDM-GCC\bin;F:\Compiler\TDM-GCC;F:\Compiler\TDM64-GCC\bin;F:\Compiler\TDM64-GCC;C:\Windows;C:\Windows\System32;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;F:\Program Files (x86)\CMake 2.8\bin;C:\Program Files\TortoiseHg
Starting debugger: F:\Compiler\TDM64-GCC\bin\gdb.exe -nx -fullname  -quiet  -args F:/Projekte/_C___N~1/GAMECO~1/NOSANC~1.EXE
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.5
Child process PID: 5572
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()
Debugger finished with status 0
Call Stack:
0 0000002B ?? ()  
« Last Edit: December 22, 2012, 06:57:25 pm by Xaymar »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #1 on: December 22, 2012, 03:50:07 pm »
I'm not quite sure what the problem is, since I've used TDM-GCC successfully (see my nightly builds which include the SFML examples). As for the posted code there are a few things that one doesn't/shouldn't do...

The default main functions usually looks like one of those and doesn't had uint32_t...
int main()
int main(int argc, char *argv[])

Since the return type is int you should also return an integer rather than a boolean:
return 0;
Or just don't write any return statement, which is fine by the C++ standard , but just for the main function!

Third you shouldn't allocate a clock dynamically or you shouldn't manually manage memory at all. The posted code does at the moment leak memory, since you never call delete on the pointer.
If you need pointer like behavior then it's advised to use std::unique_ptr (or std::shared_ptr if the resource is shared) but in most cases it's possible to handle things on the stack rather than the heap.

Try the following code and check if you also get a SEG fault:
#include <SFML/System.hpp>

int main()
{
    sf::Clock clock;
}

Also is there a specific reason why you use TDM-GCC? The official MinGW build have made an update recently and now ship with GCC 4.7.2. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Xaymar

  • Newbie
  • *
  • Posts: 10
  • No Sanctuary
    • View Profile
    • Shark Missile Interactive
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #2 on: December 22, 2012, 04:43:31 pm »
I changed the code to match what you said, but it is still causing a Segmentation Fault. However, now it partially works in my Debug configuration, which led me to check what would cause that call to fail. It seems that "-O"(and it's variances) seem to cause the crash.
Or so I thought, because when I inserted the following code before that line, it crashes again:
std::cout << "Test" << std::endl;

Current Code:
/**
 * @file main.cpp
 * @author Shark Missile Interactive
 */


#include <SFML/System.hpp>

int main(int iArgumentCount, char *cArgumentValue[]) {
        //std::cout << "Test" << std::endl; //Uncomment to crash.
        sf::Clock oClock;

        uint64_t t1 = oClock.getElapsedTime().asSeconds();
        std::cout << t1 << std::endl;

        return EXIT_SUCCESS;
}

Right now I'm completely lost as to what would cause this.

Also is there a specific reason why you use TDM-GCC? The official MinGW build have made an update recently and now ship with GCC 4.7.2. ;)

At the time of setting up the project, TDM-GCC was the most stable with the toolset we used to compile. I would switch to MinGW, but it would require the remaining team to agree, and I also would have to write a new installation 'documentation'.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #3 on: December 22, 2012, 04:57:04 pm »
Just to make sure again: You're 100% positive that you use the TDM GCC SJLJ version and don't mix debug and release modes (i.e. compiling as debug but using the release libraries of SFML)?

Also when do you get the SEG fault? Just as it starts or at exit or in between?
Have you tried to run your application in the debugger and step through everything manually?

And a last questions does it happen only with SFML or also when you just use std::vector or simply everything else? And if it's SFML, does it only happen with sf::Clock?

As for the code you posted: .asSeconds() returns a float, so don't force it into a uint64_t and if you need it as integer then use a cast (static_cast<uint64_t>). Additionally I'm not sure how crossplatform uint64_t is and thus it might be better to only use types that are known to be crossplatform and for the rest you could use sf::Int64 etc. since you're already using SFML. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Xaymar

  • Newbie
  • *
  • Posts: 10
  • No Sanctuary
    • View Profile
    • Shark Missile Interactive
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #4 on: December 22, 2012, 05:35:49 pm »
I'm fairly sure that the Bundle links provided on their websites link to the SJLJ version, since it is stated there. Libraries are mixed up either, sfml-system for release and sfml-system-d for debug (insert -s for static builds).

The Segmentation Fault seems to happen in the constructor for sf::Clock, but I do not know where, since the Call Stack shows ?? (). Debugging and stepping through seems impossible since GDB complains about "Cannot find bounds of current function" (Which is explained by the line "In ?? () ()" right before it).

It only happens with calls to SFML and it's modules. Calling OpenAL, OpenGL, RakNet and other libraries works fine.

The direct casting from float to uint64_t(unsigned long long on compilers that have it) seems to work without a problem so I see no need to change it right now, since all I want to is get this simple main() to run, however I will keep it in mind.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #5 on: December 22, 2012, 05:47:03 pm »
And you did run gdb with the debug mode?

The direct casting from float to uint64_t(unsigned long long on compilers that have it) seems to work without a problem so I see no need to change it right now, since all I want to is get this simple main() to run, however I will keep it in mind.
Well it will give you a compiler warning with -Wall and in general one should always try to get rid of all compiler warnings. ;)

Anyways I've no idea what the problem is, maybe it's a faulty compiler setup?
Strange thing is, that all the examples on my SFML build work fine and I also use TMD-GCC SJLJ 4.7.1-2 (check it out here [7zip Archive]).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Xaymar

  • Newbie
  • *
  • Posts: 10
  • No Sanctuary
    • View Profile
    • Shark Missile Interactive
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #6 on: December 22, 2012, 06:31:16 pm »
Yeah, the project is compiled and run in debug mode (compiler and linker flag -g -ggdb).

Also it is interesting to note that the binaries you linked work, the ones I compiled myself however do not. Care to share your secret of using cmake properly?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #7 on: December 22, 2012, 06:46:36 pm »
Also it is interesting to note that the binaries you linked work, the ones I compiled myself however do not. Care to share your secret of using cmake properly?
What exactly do you mean by binaries? The examples or the SFML libs itself?

There's one special trick I've to use for TDM-GCC, because TDM builds things statically by default, thus you have to explicitly tell the compiler when to link dynamically, but I don't know if that has anything to do with it. Other than that I use CMake like you would with any other compiler...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Xaymar

  • Newbie
  • *
  • Posts: 10
  • No Sanctuary
    • View Profile
    • Shark Missile Interactive
Re: Failing to compile with SJLJ SFML-2.0 binaries
« Reply #8 on: December 22, 2012, 06:51:15 pm »
Also it is interesting to note that the binaries you linked work, the ones I compiled myself however do not. Care to share your secret of using cmake properly?
What exactly do you mean by binaries? The examples or the SFML libs itself?

The dlls and libs themselves work without a problem.

There's one special trick I've to use for TDM-GCC, because TDM builds things statically by default, thus you have to explicitly tell the compiler when to link dynamically, but I don't know if that has anything to do with it. Other than that I use CMake like you would with any other compiler...

I had problems creating the dll files, so thanks for the information.

Edit: This error in particular:
Code: [Select]
mingw32-make[2]: *** No rule to make target `lib/sfml-system.a', needed by `lib/
sfml-window-2.dll'.  Stop.
mingw32-make[1]: *** [src/SFML/Window/CMakeFiles/sfml-window.dir/all] Error 2
mingw32-make: *** [all] Error 2
« Last Edit: December 22, 2012, 06:57:04 pm by Xaymar »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: [Partially Solved] Failing to compile with SJLJ SFML-2.0 binaries
« Reply #9 on: December 22, 2012, 08:07:17 pm »
Since I've automated the whole building process for the Nightly Builds, I keep a modified copy of the cmake/Macros.cmake and whenever I build for TDM I replace the existing one. You can look at the diff of both here.

Also if you build with different configs make sure that you install the libs somewhere and the make clean build, otherwise the compiler might think that one lib has already been build although the settings have changed.

And most importantly make sure that you don't mix static runtime libs and shared runtime libs (note again that TDM links them by default statically).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/