segfault at creation-class after cross-compilation for Windows

0

I try to create a prorgam using SFML 2.0 for Windows, using a Gentoo Linux with mingw32.

I don't want to recompile SFML and all it's dependencies, so i've downloaded a compiled version from the official site (version 32 bits - SJLJ)

I have compiled my code, and executed it on wine, but it segfault when i try to instanciate a class from SFML. I have tried using static or dynamic version of SFML, nothing change.

Using debug mode, it seem that the this value is not correctly initialized on SFML classes.

my compilation flags:

CXXFLAGS = -W -Wall -ggdb3 -ISFML-2.0-rc/include -DSFML_STATIC
LDFLAGS  = -LSFML-2.0-rc/lib -static-libgcc -static-libstdc++ -mwindows      \
           -lsfml-window-s-d -lsfml-graphics-s-d -lsfml-system-s-d -lws2_32

main.cpp:

#include <SFML/Window.hpp>

int main() {
  sf::VideoMode vm(800, 600);

  return 0;
}

wine error:

wine: Unhandled page fault on write access to 0x00000320 at address 0x4021e9 (thread 0026), starting debugger...
Unhandled exception: page fault on write access to 0x00000320 in 32-bit code (0x004021e9).
Register dump:
 CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b
 EIP:004021e9 ESP:0087fd78 EBP:0087fd78 EFLAGS:00010202(  R- --  I   - - - )
 EAX:00000320 EBX:7b896ff4 ECX:0087fdd4 EDX:00000258
 ESI:7ffdf000 EDI:004012b0
Stack dump:
0x0087fd78:  0087fdf8 004013bd 00000320 00000258
0x0087fd88:  00000020 0040c387 00401340 004012b0
0x0087fd98:  0087fdc8 00000000 00000001 7ffdf000
0x0087fda8:  0087fdc8 7ed71ff4 00409fc0 00418d28
0x0087fdb8:  00419370 0087fde0 004013ca 0087fd80
0x0087fdc8:  0087fde8 0040b162 00000001 0000ffff
Backtrace:
=>0 0x004021e9 VideoMode+0x9(this=0x320, modeWidth=0x258, modeHeight=0x20, modeBitsPerPixel=0x40c387) [D:\developpement\sfml-misc\release\2.0-rc1\gcc4-sjlj\debug-static\src\SFML\Window/D:/developpement/sfml-master/src/SFML/Window/VideoMode.cpp:50] in chess (0x0087fd78)
  1 0x004013bd main+0x6c() [/home/bak/projets/bjtu/server architecture/Chess/main.cpp:5] in chess (0x0087fdf8)
  2 0x004010fd in chess (+0x10fc) (0x0087fe88)
  3 0x7b85d80f in kernel32 (+0x4d80e) (0x0087fec8)
  4 0x7bc73ed0 call_thread_func_wrapper+0xb() in ntdll (0x0087fed8)
  5 0x7bc7690d call_thread_func+0x7c() in ntdll (0x0087ffa8)
  6 0x7bc73eae RtlRaiseException+0x21() in ntdll (0x0087ffc8)
  7 0x7bc4c78e call_dll_entry_point+0x61d() in ntdll (0x0087ffe8)
  8 0xf767106d wine_call_on_stack+0x1c() in libwine.so.1 (0x00000000)
  9 0xf767112b wine_switch_to_stack+0x2a() in libwine.so.1 (0xffd55c28)
  10 0x7bc51e6f LdrInitializeThunk+0x2ee() in ntdll (0xffd55c98)
  11 0x7b86371a __wine_kernel_init+0xa19() in kernel32 (0xffd56e38)
  12 0x7bc5269b __wine_process_init+0x25a() in ntdll (0xffd56eb8)
  13 0xf766e5e2 wine_init+0x291() in libwine.so.1 (0xffd56f28)
  14 0x7bf0106b main+0x7a() in <wine-loader> (0xffd57378)
  15 0xf74b6596 __libc_start_main+0xe5() in libc.so.6 (0xffd573f8)
0x004021e9 VideoMode+0x9 [D:\developpement\sfml-misc\release\2.0-rc1\gcc4-sjlj\debug-static\src\SFML\Window/D:/developpement/sfml-master/src/SFML/Window/VideoMode.cpp:50] in chess: movl   %edx,0x0(%eax)

VideoMode.cpp:50 refer to the end of contructor, like with others SFML classes i've tried to use.

The this variable is not correctly initialised:

 =>0 0x004021e9 VideoMode+0x9(this=0x320, modeWidth=0x258, ...

this take the value of the first param, and all others values are shifted (fisrt arg has the second value, ...)

I've tested with severals classes with the same result.

From wich may be the problem ?
I've thought a difference between calling conventions, but i'm not sure.

c++
segmentation-fault
cross-compiling
sfml
asked on Stack Overflow Dec 21, 2012 by BAK • edited Dec 26, 2012 by BAK

1 Answer

1

It appears that you init the VideoMode for SFML in a wrong way, instead, try to create a Window object with a VideoMode as first parameter, like in the forward example :

sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");

I guess turorials should be helpful from here, but it could explain why just allocating a VideoMode from raw is causing segfault.

answered on Stack Overflow Dec 21, 2012 by tsukasan

User contributions licensed under CC BY-SA 3.0