Allegro 5 problem on Linux (segmentation fault)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
bighax
Posts: 3
Joined: Feb 19, 2017 14:18

Allegro 5 problem on Linux (segmentation fault)

Post by bighax »

Code: Select all

#include "allegro5/allegro.bi"

al_init()

var display = al_create_display(800, 600)

if display = NULL then
	print "al_create_display() failed"
	end 1
end if

var events = al_create_event_queue()

if events = NULL then
	print "failed to create event_queue"
	end 1
end if

al_destroy_event_queue(events)	
al_destroy_display(display)

Looks simple, right? But whenever I run this, it just says "Segmentation fault".

If I remove the parts relating to display, it works. Same if I drop the event queue parts. But if I keep both of them, it responds with a segmentation fault. Does anyone have any idea of what's going on? It's the same even when I just copy the example from here: https://github.com/freebasic/fbc/blob/m ... /hello.bas. Thanks in advance.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Allegro 5 problem on Linux (segmentation fault)

Post by D.J.Peters »

On Linux allegro5/alegro.bi are linked to liballegro.so you are sure yours is V5.0 ?

On Windows allegro5/alegro.bi linked to allegro-5.0.10-md.dll

Joshy
bighax
Posts: 3
Joined: Feb 19, 2017 14:18

Re: Allegro 5 problem on Linux (segmentation fault)

Post by bighax »

OK, I've fixed the problem, but I don't really know what I did. I don't think reinstalling allegro or freebasic should have done anything, since those were the same packages. Anyway, I've got another problem:

Code: Select all

al_draw_text(font, al_map_rgb(255,255,255), 100, 100, 0, "Hello!")
Again, it's lifted straight from the examples page, and it throws this error: Aborting due to runtime error 12 ("segmentation violation" signal). If I remove that line of code, the program runs. What could be the issue here?

Edit: apparently I have to do something with pointers, but whatever I try, it either throws the same error or just freezes (whenever I try to Allocate memory). I really don't get pointers.

By the way, the first error was fixed by adding -e option to compiler.
bighax
Posts: 3
Joined: Feb 19, 2017 14:18

Re: Allegro 5 problem on Linux (segmentation fault)

Post by bighax »

Code: Select all

#include "allegro5/allegro.bi"

al_init()

dim message as string
dim message_pointer as zstring ptr

message = "is it working yet?"
message_pointer = allocate(Len(message)+1)
*message_pointer = message

print *message_pointer
deallocate(message_pointer)

I think I get pointers now. But I've got another problem. The above program works fine, but if I add these three lines at the end of it:

Code: Select all

var display = al_create_display(800, 600)
print "display created"
al_destroy_display(display)
The display does get created, but the message "display created" does not appear. And if compiled without the -e option, it just throws the segmentation fault again. Can anyone hack it?
Plasma
Posts: 205
Joined: May 27, 2005 5:22
Location: Earth
Contact:

Re: Allegro 5 problem on Linux (segmentation fault)

Post by Plasma »

FB's print isn't going to work in allegro graphics modes. You need to use allegro's textout function.
Post Reply