2013-12-08 171 views
4

我在这里遇到了问题。调用SDL_SetVideoMode时出现分段错误

我是一个组的一部分,我们正在使用SDL进行图形处理。当我运行我们的test_SDL.cc程序(只是为了查看所有设置正确)时,我是唯一一个出现分段错误的人。

下面是相关代码:

int main(int argc, char** arg) 
{ 
    // Initializing 
    if(-1 == SDL_Init(SDL_INIT_EVERYTHING)) 
     return 1; 

    SDL_Surface* screen{nullptr}; 
    SDL_Surface* hello{nullptr}; 

    screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); 
    ... 
} 

当SDL_SetVideoMode(...)执行我得到的分割故障。任何可能的线索?

我在Mac OS上运行的小牛队,并与终端

Pingul % gcc-mp-4.8 -lstdc++ -std=c++11 -Wall -Wpedantic `sdl-config --cflags --libs` test_SDL.cc 

编译如果它可以有所作为的其他所有在我的组使用的Ubuntu。感谢所有帮助!

编辑: 崩溃关系 过程:a.out的[918] 路径:/Users/USER/Documents/*/a.out 标识符:a.out的 版本:0 编码类型:X86-64 (母语) 父进程:zsh的[297] 负责:端子[155] 用户ID:501

Date/Time:  2013-12-08 21:30:32.860 +0100 
OS Version:  Mac OS X 10.9 (13A603) 
Report Version: 11 
Anonymous UUID: EF22B2C8-6B58-F80F-184F-61D6ECE0B474 


Crashed Thread: 1 

Exception Type: EXC_CRASH (SIGSEGV) 
Exception Codes: 0x0000000000000000, 0x0000000000000000 

Thread 0:: Dispatch queue: com.apple.main-thread 
0 libSDL-1.2.0.dylib    0x000000010d59c3a9 -[SDL_QuartzWindow display] + 33 
1 com.apple.AppKit    0x00007fff9460a681 __67-[NSWindow  _updateSettingsSendingScreenChangeNotificationIfNeeded:]_block_invoke + 237 
2 com.apple.AppKit    0x00007fff9460a548 NSPerformWithScreenUpdatesDisabled + 65 
3 com.apple.AppKit    0x00007fff9460a4f7 -[NSWindow  _updateSettingsSendingScreenChangeNotificationIfNeeded:] + 197 
4 com.apple.AppKit    0x00007fff946027e1 -[NSWindow _setFrame:updateBorderViewSize:] + 914 
5 com.apple.AppKit    0x00007fff94601d5e -[NSWindow _oldPlaceWindow:] + 652 
6 com.apple.AppKit    0x00007fff9460118c -[NSWindow _setFrameCommon:display:stashSize:] +  1633 
7 com.apple.AppKit    0x00007fff946155bc -[NSWindow setFrameOrigin:] + 369 
8 com.apple.AppKit    0x00007fff9483d561 -[NSWindow center] + 278 
9 libSDL-1.2.0.dylib    0x000000010d59a386 QZ_SetVideoMode + 1652 
10 libSDL-1.2.0.dylib    0x000000010d5915a9 SDL_SetVideoMode + 906 
11 a.out       0x000000010d46c7d4 SDL_main + 203 
12 a.out       0x000000010d46c0bb -[SDLMain applicationDidFinishLaunching:] + 49 
13 com.apple.CoreFoundation  0x00007fff935c7fcc  __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12 
14 com.apple.CoreFoundation  0x00007fff934bbc5d _CFXNotificationPost + 2893 
15 com.apple.Foundation   0x00007fff9419d4aa -[NSNotificationCenter  postNotificationName:object:userInfo:] + 68 
16 com.apple.AppKit    0x00007fff944e7b79 -[NSApplication _postDidFinishNotification] + 289 
17 com.apple.AppKit    0x00007fff944e78ac -[NSApplication _sendFinishLaunchingNotification]  + 195 
18 com.apple.AppKit    0x00007fff944e4796 -[NSApplication(NSAppleEventHandling)  _handleAEOpenEvent:] + 570 
19 com.apple.AppKit    0x00007fff944e41eb -[NSApplication(NSAppleEventHandling)  _handleCoreEvent:withReplyEvent:] + 242 
20 com.apple.Foundation   0x00007fff941bbeaa -[NSAppleEventManager  dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 294 
21 com.apple.Foundation   0x00007fff941bbd1d _NSAppleEventManagerGenericHandler + 106 
22 com.apple.AE     0x00007fff8de11e1f aeDispatchAppleEvent(AEDesc const*, AEDesc*,  unsigned int, unsigned char*) + 381 
23 com.apple.AE     0x00007fff8de11c32 dispatchEventAndSendReply(AEDesc const*, AEDesc*)  + 31 
24 com.apple.AE     0x00007fff8de11b36 aeProcessAppleEvent + 315 
25 com.apple.HIToolbox    0x00007fff8e0a55f1 AEProcessAppleEvent + 56 
26 com.apple.AppKit    0x00007fff944e00f6 _DPSNextEvent + 1026 
27 com.apple.AppKit    0x00007fff944df8db -[NSApplication  nextEventMatchingMask:untilDate:inMode:dequeue:] + 122 
28 com.apple.AppKit    0x00007fff944d39cc -[NSApplication run] + 553 
29 a.out       0x000000010d46c6df main + 1305 
30 libdyld.dylib     0x00007fff936a05fd start + 1 

Thread 1 Crashed: 
0 libsystem_kernel.dylib   0x00007fff8a4c4e6a __workq_kernreturn + 10 
1 libsystem_pthread.dylib   0x00007fff93697f08 _pthread_wqthread + 330 
2 libsystem_pthread.dylib   0x00007fff9369afb9 start_wqthread + 13 

Thread 2:: Dispatch queue: com.apple.libdispatch-manager 
0 libsystem_kernel.dylib   0x00007fff8a4c5662 kevent64 + 10 
1 libdispatch.dylib    0x00007fff8e52343d _dispatch_mgr_invoke + 239 
2 libdispatch.dylib    0x00007fff8e523152 _dispatch_mgr_thread + 52 

Thread 3: 
0 libsystem_kernel.dylib   0x00007fff8a4c4e6a __workq_kernreturn + 10 
1 libsystem_pthread.dylib   0x00007fff93697f08 _pthread_wqthread + 330 
2 libsystem_pthread.dylib   0x00007fff9369afb9 start_wqthread + 13 

Thread 4: 
0 libsystem_kernel.dylib   0x00007fff8a4c4e6a __workq_kernreturn + 10 
1 libsystem_pthread.dylib   0x00007fff93697f08 _pthread_wqthread + 330 
2 libsystem_pthread.dylib   0x00007fff9369afb9 start_wqthread + 13 

Thread 5: 
0 libsystem_kernel.dylib   0x00007fff8a4c4e6a __workq_kernreturn + 10 
1 libsystem_pthread.dylib   0x00007fff93697f08 _pthread_wqthread + 330 
2 libsystem_pthread.dylib   0x00007fff9369afb9 start_wqthread + 13 

Thread 6: 
0 libsystem_kernel.dylib   0x00007fff8a4c4e6a __workq_kernreturn + 10 
1 libsystem_pthread.dylib   0x00007fff93697f08 _pthread_wqthread + 330 
2 libsystem_pthread.dylib   0x00007fff9369afb9 start_wqthread + 13 

Thread 1 crashed with X86 Thread State (64-bit): 
    rax: 0x0000000002000170 rbx: 0x000000010e081000 rcx: 0x000000010e080f28 rdx: 0x0000000000000000 
    rdi: 0x0000000000000004 rsi: 0x0000000000000000 rbp: 0x000000010e080f50 rsp: 0x000000010e080f28 
    r8: 0x00007fff922df8d7 r9: 0x0000000000000164 r10: 0x0000000000000000 r11: 0x0000000000000246 
    r12: 0x0000000000000000 r13: 0x0000000000000000 r14: 0x0000000000070001 r15: 0x0000000000001003 
    rip: 0x00007fff8a4c4e6a rfl: 0x0000000000000246 cr2: 0x000000010f352000 

Logical CPU:  0 
Error Code:  0x02000170 
Trap Number:  133 

并且还

VM Region Summary: 
ReadOnly portion of Libraries: Total=155.7M resident=54.7M(35%) swapped_out_or_unallocated=101.0M(65%) 
Writable regions: Total=71.8M written=2836K(4%) resident=3764K(5%) swapped_out=0K(0%) unallocated=68.1M( 95%) 

REGION TYPE      VIRTUAL 
===========      ======= 
CG image        4K 
CG shared images     212K 
Dispatch continuations    8192K 
Kernel Alloc Once      8K 
MALLOC        36.6M 
MALLOC (admin)      32K 
Memory Tag 242      12K 
STACK GUARD      56.0M 
Stack        10.6M 
VM_ALLOCATE      16.3M 
__DATA        19.3M 
__IMAGE        528K 
__LINKEDIT       66.1M 
__TEXT        89.6M 
__UNICODE       544K 
mapped file      28.2M 
shared memory       4K 
===========      ======= 
TOTAL        332.2M 

Model: MacBookAir4,1, BootROM MBA41.0077.B0F, 2 processors, Intel Core i5, 1.6 GHz, 4 GB, SMC 1.74f4 
Graphics: Intel HD Graphics 3000, Intel HD Graphics 3000, Built-In, 384 MB 
Memory Module: BANK 0/DIMM0, 2 GB, DDR3, 1333 MHz, 0x80AD, 0x484D54333235533642465238432D48392020 
Memory Module: BANK 1/DIMM0, 2 GB, DDR3, 1333 MHz, 0x80AD, 0x484D54333235533642465238432D48392020 
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0xE9), Broadcom BCM43xx 1.0 (5.106.98.100 .22) 
Bluetooth: Version 4.2.0f6 12982, 3 services, 23 devices, 1 incoming serial ports 
Network Service: Wi-Fi, AirPort, en0 
Serial ATA Device: APPLE SSD TS128C, 121,33 GB 
USB Device: FaceTime Camera (Built-in) 
USB Device: Hub 
USB Device: Apple Internal Keyboard/Trackpad 
USB Device: BRCM20702 Hub 
USB Device: Bluetooth USB Host Controller 
USB Device: Hub 
Thunderbolt Bus: MacBook Air, Apple Inc., 8.1 

我希望这是相关的信息。请告诉我,如果我格式化这个怪异以及。

+1

你/你的小组成员正在使用什么版本的sdl? – user1810087

+1

@itwasntpete我们正在使用1.2.15。在您的建议后,我尝试将32更改为24,并查看所有可用选项。唯一的工作是SDL_FULLSCREEN,所有其他也导致了分段错误。你有洞察力为什么?如果没有,我会用我得到的,但会很有趣,否则以及:) – pingul

+1

你试过[SDL_GetVideoInfo()](http://www.libsdl.org/release/SDL-1.2。 15/docs/html/sdlvideoinfo.html)看看“可能”最好?另外,请发布一些错误。 – user1810087

回答

1

修复每像素位并不是一个好主意。也不是每个mac-os都支持sdl上的32位。尝试一些其他的价值。 0用于自动分配,它通常不在mac上运行。我认为24应该这样做。

screen = SDL_SetVideoMode(640, 480, 24, SDL_SWSURFACE); 

您还可以使用SDL_GetVideoInfo();来确定您应该使用哪种模式。