调用SDL_SetVideoMode时出现分段错误

时间:2013-12-08 17:41:09

标签: c++ sdl

我在解决这里的问题时遇到了问题。

我是小组的成员,我们正在使用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 Mavericks上运行,并使用终端

进行编译
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 个答案:

答案 0 :(得分:1)

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

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

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

相关问题