我尝试在Windows上使用SFML 2.0,使用带有mingw32的Gentoo Linux创建一个程序。
我不想重新编译SFML和它的所有依赖关系,所以我从官方网站下载了一个编译版本(版本32位- SJLJ)
我已经编译了我的代码,并在wine上执行它,但是当我尝试从SFML实例化一个类时,它会出现分段错误。我试过使用静态或动态版本的SFML,没有任何变化。
使用调试模式,似乎this
值在SFML类上没有正确初始化。
我的编译标志:
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: 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:developpementsfml-miscrelease2.0-rc1gcc4-sjljdebug-staticsrcSFMLWindow/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:developpementsfml-miscrelease2.0-rc1gcc4-sjljdebug-staticsrcSFMLWindow/D:/developpement/sfml-master/src/SFML/Window/VideoMode.cpp:50] in chess: movl %edx,0x0(%eax)
VideoMode.cpp:50
指的是构造函数的结束,就像我尝试使用的其他SFML类一样。
this
变量初始化不正确:
=>0 0x004021e9 VideoMode+0x9(this=0x320, modeWidth=0x258, ...
this
取第一个参数的值,所有其他值移位(第一个参数有第二个值,…)
我已经用几个类测试了相同的结果。
问题出在哪里?
似乎您以错误的方式为SFML初始化VideoMode,相反,尝试创建一个Window对象,将VideoMode作为第一个参数,如向前的示例:
sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window");
我想教程应该从这里有所帮助,但它可以解释为什么只是从raw分配VideoMode会导致段错误。