|
game crashing on al_wait_for_event callee |
iam_donald
Member #14,318
May 2012
|
Hi, 1void run_core(Core * core)
2 {
3 al_start_timer(core->timer);
4 Background * background = init_background("../frames/frames.json");
5 while(not end_run)
6 {
7 ALLEGRO_EVENT event;
8
9 al_wait_for_event(core->queue, &event);
10 if(event.type == ALLEGRO_EVENT_TIMER)
11 {
12 /* update physics */
13 draw_background(background->frame);
14 frame_step(background);
15 blit();
16 }
17 else if(event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { end_run = true; }
18 else if(event.type == ALLEGRO_EVENT_KEY_DOWN)
19 {
20 ALLEGRO_KEYBOARD_STATE state;
21 al_get_keyboard_state(&state);
22 /* get input update */
23 }
24 }
25 destroy_background(background);
26}
Prior to calling this function, I have calls to al_create_event_queue, and al_register_event_source for the queue,timer and keyboard respectively. I also assert that the calls succeeded by checking for NULL. Running it generates this trace:
Process: furi_debug [660] Date/Time: 2012-05-25 18:08:27.306 +0000 Interval Since Last Report: 198172 sec Crashed Thread: 5 Exception Type: EXC_BAD_ACCESS (SIGSEGV) VM Regions Near 0x97: Application Specific Information: Thread 0:: Dispatch queue: com.apple.main-thread Thread 1:: Dispatch queue: com.apple.libdispatch-manager Thread 2: Thread 3: Thread 4: Thread 5 Crashed: Thread 5 crashed with X86 Thread State (64-bit): I have also attached the full trace report. How do I fix this? Thanks. |
Trent Gamblin
Member #261
April 2000
|
Hmm. Did you call al_init? al_create_timer? al_install_keyboard? Need more code.
|
iam_donald
Member #14,318
May 2012
|
Yes I did. 1static void init() { assert(al_init()); }
2
3ALLEGRO_EVENT_QUEUE * init_event_queue()
4 {
5
6 ALLEGRO_EVENT_QUEUE * queue = NULL;
7 queue = al_create_event_queue();
8 if(not queue ) { perror_with_context("Failed to create ALLEGRO_EVENT_QUEUE", __LINE__, __FILE__); exit(EXIT_FAILURE); }
9 return queue;
10 }
11
12 ALLEGRO_TIMER * init_timer(ALLEGRO_EVENT_QUEUE * queue)
13 {
14 ALLEGRO_TIMER * timer = al_create_timer(ALLEGRO_BPS_TO_SECS(FPS));
15 if(not timer) { perror_with_context("Failed to create ALLEGRO_TIMER", __LINE__, __FILE__); exit(EXIT_FAILURE); }
16 else { al_register_event_source(queue, al_get_timer_event_source(timer)); }
17 return timer;
18 }
19
20 ALLEGRO_EVENT_SOURCE * init_input(ALLEGRO_EVENT_QUEUE * queue)
21 {
22 ALLEGRO_EVENT_SOURCE * input;
23 if(not al_install_keyboard()) { perror_with_context("al_install_keyboard failed", __LINE__, __FILE__); exit(EXIT_FAILURE); }
24 else
25 {
26 input = al_get_keyboard_event_source();
27 if(not input) { perror_with_context("Failed to create ALLEGRO_EVENT_SOURCE", __LINE__, __FILE__); exit(EXIT_FAILURE);}
28 else { al_register_event_source(queue, input); }
29 }
30 return input;
31 }
32
33void init_core(Core * core)
34 {
35 core->queue = init_event_queue(core->queue);
36 core->display = init_display(core->queue, W960_H540);
37 core->timer = init_timer(core->queue);
38 core->input = init_input(core ->queue);
39 /* init_font(); */
40 /* init audio */
41 /* init physics */
42 }
I went ahead and debugged it in GDB, the output:
Starting program: /Volumes/Work/dev/furi/core/furi_debug Breakpoint 1, al_wait_for_event (queue=0x101132900, ret_event=0x103125bc8) at events.c:330 Program received signal EXC_BAD_ACCESS, Could not access memory. I'm still unsure of what is causing the crash, the ALLEGRO_EVENT_QUEUE object passed is not NULL. |
Peter Wang
Member #23
April 2000
|
How about the timer in the timer thread?
|
Trent Gamblin
Member #261
April 2000
|
I don't see anything there that would cause it. Can you upload a little project zip so I can try it out. Source code?
|
iam_donald
Member #14,318
May 2012
|
Peter wang: The timer in the timer thread is created by allegro when al_wait_for_event is called, the library takes care of initializing it I think. Trent Gamblin: I've attached the source zip and a json file, the source loads images using the json file attached. Please edit the file with your own image file paths. Besides Allegro, the other dependencies you be needing are tmalloc of gperftools (http://code.google.com/p/gperftools/) and jansson (http://www.digip.org/jansson/). The makefile uses clang as the compiler, gcc works fines as well. Make commands are 'make clean', 'make furi', 'make furi_debug'. Thanks for taking a look at this for me. |
Peter Wang
Member #23
April 2000
|
Thread 5 Crashed: 0 liballegro-debug.5.0.dylib 0x000000010bbd31ad timer_thread_handle_tick + 77 (timernu.c:135) 1 liballegro-debug.5.0.dylib 0x000000010bbd3127 timer_thread_proc + 119 (timernu.c:111) 2 liballegro-debug.5.0.dylib 0x000000010bc71260 thread_proc_trampoline + 48 (uxthread.c:37) 3 libsystem_c.dylib 0x00007fff8b2a98bf _pthread_start + 335 4 libsystem_c.dylib 0x00007fff8b2acb75 thread_start + 13 This says the crash is in the timer thread. I think you are on the wrong path with al_wait_for_event.
|
Trent Gamblin
Member #261
April 2000
|
Yikes. I don't have time to install those deps and run and debug it right now. If you can break it down into a small test case then I can try that. Otherwise wait until tomorrow or something. But what Peter said is true.
|
iam_donald
Member #14,318
May 2012
|
Fixed it. Thanks for the guidance. |
Peter Wang
Member #23
April 2000
|
It was a bug in your program, correct? Allegro bugs keep me up at night.
|
iam_donald
Member #14,318
May 2012
|
Yeah I botched a couple of mallocs in my code, silly me . You guys [contributors] are doing a fine job with Allegro. It's really powerful. Your work is very much appreciated |
|