1
\$\begingroup\$

I have consistently segfaulted trying to load a TMX file into a *map.

int main(int argc, char *argv[])
{
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;
    ALLEGRO_KEYBOARD_STATE keyboard_state;
    ALLEGRO_MAP *map = al_open_map("data/maps", "TestMap.tmx");
...

Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target: 
Debug
Adding source dir: /home/X/Desktop/Programming/C/AllegroRoboticsTest/
Adding source dir: /home/X/Desktop/Programming/C/AllegroRoboticsTest/
Adding file: /home/X/Desktop/Programming/C/AllegroRoboticsTest/bin/Debug/AllegroRoboticsTest
Changing directory to: /home/X/Desktop/Programming/C/AllegroRoboticsTest/.
Set variable: LD_LIBRARY_PATH=.:/usr/local/lib:/opt/opencascade/lib
Starting debugger: /usr/bin/gdb -nx -fullname -quiet  -args /home/X/Desktop/Programming/C/AllegroRoboticsTest/bin/Debug/AllegroRoboticsTest
done
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 8.1
Program received signal SIGSEGV, Segmentation fault.
In al_get_standard_path () (/usr/lib/liballegro.so.5.2)
#2  0x00005555555563ba in main (argc=1, argv=0x7fffffffe3a8) at /home/X/Desktop/Programming/C/AllegroRoboticsTest/main.c:45

At first I thought, maybe I just didn't build the library right, so I rebuilt it 2 more times, once as a static and another as a shared library.

The interesting thing is that it builds just fine when using the cmake files that came in the example.

I cannot recreate it though.

Example here.


enter image description here

This is the callback after I moved the open map command into it's usual place, directly from the example that comes with allegro_tiled.

// If MAP_FOLDER is relative to the working directory and not the running
// executable, then add a call to `al_find_resources_as(RELATIVE_TO_CWD);`
// before calling `al_open_map()`.
//al_find_resources_as(RELATIVE_TO_CWD);
map = al_open_map("data/maps", "TestMap.tmx");
int map_total_width = al_get_map_width(map) * al_get_tile_width(map);
int map_total_height = al_get_map_height(map) * al_get_tile_height(map);

// Draw the map
al_clear_to_color(al_map_rgb(0, 0, 0));
al_draw_map_region(map, map_x, map_y, screen_width, screen_height, 0, 0, 0);
al_flip_display();

   ...
   Setting breakpoints
   Debugger name and version: GNU gdb (GDB) 8.1
   Child process PID: 25749
   In ____strtoll_l_internal () (/usr/lib/libc.so.6)
   #3  0x0000555555556615 in main (argc=1, argv=0x7fffffffe3a8) at /home/X/Desktop/Programming/C/AllegroRoboticsTest/main.c:114
\$\endgroup\$
1
  • \$\begingroup\$ Just out of curiosity... Did you check that the map successfully loaded? Always check for NULL pointers. Especially when loading files from a program. It's a very common issue when you start using Allegro \$\endgroup\$
    – rlam12
    Apr 17, 2018 at 15:04

1 Answer 1

2
\$\begingroup\$

Looks like you are not initializing the library with al_init call.

It tries to retrieve some standard directory to know where is the map stored, but crashes because these were not initialized.

\$\endgroup\$
1
  • \$\begingroup\$ I initialized all the libraries, using the example code that comes with tiled, and then recieved another segfault, this one throwing an internal callstack within libc, I will update my post with this. \$\endgroup\$
    – dotJson
    Feb 23, 2018 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .