Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Code not working when check allegro_init() != 0

This thread is locked; no one can reply to it. rss feed Print
Code not working when check allegro_init() != 0
alex alex
Member #18,271
September 2020

Hello everybody,

Me introducing myself (you can skip it as it is boring, probably) :

I'm new here so I wish to introduce myself a little bit ...
My name is Alex, I'm from France, I love music and keyboards a lot, and I used to enjoy C programming a lot when I was younger ... That was 25 years ago ... And I used Allegro at this time -_- Then I never did any coding for the past 25 years ... Right now I'm doing a software for my synthesizer, some audio conversion stuff, but I went to a point when the dos command line is not enough anymore, so I remembered how great and easy was Allegro !

My question :

I'm coding on Windows 8 and I'm using MingW32, the last version. Yesterday it was a huuuuuge pain is the *** to make Allegro working. I don't even talk about compiling it, I was completely out of luck and I gave up.
No problem, I installed a binary of the 4.4 (or so...) version, and now it's working.

Now something's really weird happens. Every example codes that I try don't work until I change a single thing :
The original code is :

if (allegro_init() != 0)
return 1;

This make the compiled code not working, nothing happen when I launch it.

Then if I change the condition from != to == , the code launches perfectly ...

I don't get it, is it some kind of compatibility issue ?
Just the same with every pieces of examples available from the website ...

Thanks for the help
Alex

PS : I would like to use the ADIME dialogs/gui library, once again I have no luck compiling it :( I'm really not a nerd. Is there any binary versions of it for windows available ? Or any other similar libraries, already compiled and that looked more or less like windows ?

Niunio
Member #1,975
March 2002
avatar

Welcome back.

On Allegro 5 it is al_init.

Right now it returns boolean value TRUE (non zero) or FALSE (zero). So:

  if (al_init ()) return 1;

If you're using older Allegro, it uses inverse logic. Then for the same result you should use it as:

  if (!allegro_init ()) return 1;

-----------------
Current projects: Allegro.pas | MinGRo

dthompson
Member #5,749
April 2005
avatar

Niunio said:

Right now it returns boolean value TRUE (non zero) or FALSE (zero).

Yes indeed - Allegro 5's al_init returns FALSE if there's a problem.

I always found A4's install_* functions to to be unintuitive, because things like create_bitmap were truthy when they succeeded. So, I normally wrote the conditions like this:

if(allegro_init() != 0)
    throw_a_big_error();

if(install_keyboard() != 0)
    throw_another_error();

______________________________________________________
Website. It was freakdesign.bafsoft.net.
This isn't a game!

alex alex
Member #18,271
September 2020

Thank you a lot for your answers. So it is a compatibility problem between the code and my Allegro version, hopefully there is no other issues and I can focus on my code again. Thanks again,
Alex

RmBeer2
Member #16,660
April 2017
avatar

hello @alex alex , welcome to Allegro! :D

You can give yourself a good introduction in the offtopic forum or even fill out your profile. :)

About of allegro_init() : https://liballeg.org/stabledocs/en/alleg000.html#install_allegro

You can see that it returns 0 if it works correctly, which if it returns any value there was an error. Modify != To == can continue, but this will lead to more errors.

You also don't seem to make it clear that you're using Allegro 5 at any point.

If you want to continue programming with Allegro 4 you have djgpp.

You can found documentations for both libraries here:

Allegro 4: https://liballeg.org/stabledocs/en/allegro.html
Allegro 5: https://liballeg.org/a5docs/trunk/

Examples of Allegro 5 here:

https://github.com/liballeg/allegro5/tree/master/examples

More info here:

https://liballeg.org/

If you have any problem, do not hesitate to ask. :)

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for Emperor 2020!

bamccaig
Member #7,536
July 2006
avatar

I'm rather confused. OP claims to be using Allegro 4. Allegro 5 is irrelevant. It's rather strange that it "launches perfectly" when ignoring the error status of initializing Allegro though.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

If allegro_init doesn't return 0, it means the library failed to install. This typically happens when the runtime library version doesn't match the compiled version of allegro. It means you have bad dlls somewhere.

LennyLen
Member #5,313
December 2004
avatar

RmBeer2 said:

If you want to continue programming with Allegro 4 you have djgpp.

Why would he use a DOS compiler when he clearly states he's using Windows 8? MinGW and A4 work fine together.

alex alex
Member #18,271
September 2020

Thank you RmBeer2 for the answer. I'm having a look at the extremely well done tutorials provided in your post. Such a huge step from the last time I used Allegro, it was in the early 90's if I remember well ... I made a gameboy emulator at this time with the help of the library, there was a nice visual debugger, it was pure fun. Of course I used DJGPP at this time.

Now, Mingw seems to work perfectly for what I do. I started my new audio software with it, it was supposed to work on the line command only, but as it grows, I need a Gui now.

I didn't install Allegro 5. I really tried. Some examples worked, while some others didn't. While they compiled with no error, they had windows give me an error at launch. My tries to compile the fifth installment were a true nightmare. You're supposed to know so much in order to do it successfully, and seriously I just wanted to progress in my coding.

As far as I can remember, I installed Allegro 4.4, an already compiled version. At the exception of the allegro init condition, every examples now work perfectly, how would it be possible that the library didn't install properly ?
Well perhaps because I installed Allegro 4.0 first, then added the Allegro 4.2 files over it, then the 4.4 ... ahaha, it's a little bit messy but it does the job for my needs.

RmBeer2
Member #16,660
April 2017
avatar

@LennyLen :
Djgpp works on windows too, and is still supported, so it can be used on windows 8 too.

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for Emperor 2020!

Arthur Kalliokoski
Second in Command
February 2005
avatar

RmBeer2 said:

Djgpp works on windows too, and is still supported, so it can be used on windows 8 too.

True only for 32 bit windows, right? How many people are still using 32 bit OS'es?

The only way Trump is going to be involved in a landslide is if the land surrounding the White House collapses into the Earth's core. -- bamccaig

Niunio
Member #1,975
March 2002
avatar

How many people are still using 32 bit OS'es?

Since 64bits OSes are able to run 32bits programs, who cares. IMO if you don't have very high RAM needs, differences are negligible. I mostly compile for 32bit.

-----------------
Current projects: Allegro.pas | MinGRo

Peter Hull
Member #1,136
March 2001

Niunio said:

Since 64bits OSes are able to run 32bits programs, who cares.

AFAIK 64bit OSes are not able to run 32bit DOS programs.
(Should be possible under DOSbox though, but I've never had much luck with that)

Audric
Member #907
January 2001

If you use a Windows port of DJGPP, you're cross-compiling a DOS executable. It means you can only link DOS ports of libraries, and you're building a program that can only talk to the graphic card through VGA or VESA, instead of DirectX / Direct3D / GDI.

I can confirm mingw32 (the windows version of mingw-gcc) is a fine way to use your DJGPP experience on a windows machine, because they both have a common close ancestor : gcc

Arthur Kalliokoski
Second in Command
February 2005
avatar

Niunio said:

Since 64bits OSes are able to run 32bits programs, who cares. IMO if you don't have very high RAM needs, differences are negligible. I mostly compile for 32bit.

It's the 16 bit startup stub that Windows trips over, I know from experience.

The only way Trump is going to be involved in a landslide is if the land surrounding the White House collapses into the Earth's core. -- bamccaig

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

DJGPP is for compiling DOS executables. MinGW is for compiling Windows executables. This is not difficult people.

And vanilla MinGW is outdated and decrepit. Use MinGW-W64 instead.

Niunio
Member #1,975
March 2002
avatar

AFAIK 64bit OSes are not able to run 32bit DOS programs.

I was talking in general, but yes, you're right: DOSbox or something.

Why you didn't have luck with that? DOSbox is quite straightforward.

-----------------
Current projects: Allegro.pas | MinGRo

Doctor Cop
Member #16,833
April 2018
avatar

Hey Alex, what do you do for a living?
I'm wondering what people from other professions know programming.

Rodolfo Lam
Member #16,045
August 2015

I second Mayor Reynalda there, minGW-w64 is quite nice and very actively supported. Vainilla MinGW seems to be kinda abandoned nowadays.

Peter Hull
Member #1,136
March 2001

Niunio said:

Why you didn't have luck with that? DOSbox is quite straightforward.

I wanted to run 3dspryjinx (when it was new, my PC was too weak to run it!) and I was never able to get it to work without crashing.

Arthur Kalliokoski
Second in Command
February 2005
avatar

DOSbox won't allow instructions that were implemented after the 486.

The only way Trump is going to be involved in a landslide is if the land surrounding the White House collapses into the Earth's core. -- bamccaig

RmBeer2
Member #16,660
April 2017
avatar

3dspryjinx is a very cool game, i've already played it from win98. :P

🌈🌈🌈 🌟 Web of BlackRook 🌟 YouTube 🌟 🌈🌈🌈

Rm Beer for Emperor 2020!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Go to: