Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » We must post bugs and squash them***

This thread is locked; no one can reply to it. rss feed Print
We must post bugs and squash them***
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

MiquelFire
Member #3,110
January 2003
avatar

If size() returns 0, then i would be 4 billion (too lazy to look up the number), assuming the cast to unsigned treats negative numbers that way.

I feel like that's not the bug you're asking us to find though.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

SiegeLord
Member #7,827
October 2006
avatar

#include <SDL2/SDL.h>
#include <SDL2/SDL_timer.h>
 
int main(int argc, char *argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window* win = SDL_CreateWindow("Welcome to SDL",
                                       SDL_WINDOWPOS_CENTERED,
                                       SDL_WINDOWPOS_CENTERED,
                                       1000, 1000, 0);
    SDL_Delay(2000);
}

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Darío B.
Member #16,705
July 2017
avatar

When i reaches 0 and it substracts 1, it wraps around to the maximum value of unsigned int. Therefore, the loop never ends.

Peter Hull
Member #1,136
March 2001

GCC knows!

Quote:

<source>:4:43: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]

(strangely, clang does too but it's not reported, even with -W -Wall)

Elias
Member #358
May 2000

SiegeLord said:

SDL_Init(SDL_INIT_EVERYTHING);

Ohhh, can we have al_init_everything()? Instead of:

Maybe with a bonus version that also creates a display and timer and event queue with everything attached, and a call to al_reserve_samples? :D

queue = al_init_everything_ex(1280, 720, 60);
// can get the created display with al_get_current_display()

--
"Either help out or stop whining" - Evert

Erin Maus
Member #7,537
July 2006
avatar

#SelectExpand
1#call-to-action button { 2 border: none; 3 outline: none; 4 5 width: 320px; 6 7 font-family: inherit; 8 font-size: 3.5rem; 9 10 color: #eeeeee; 11 text-shadow: 1px 1px #000000; 12 13 background: none; 14 border-image: url('border3.png') 24 24 fill / 24px 24px repeat; 15} 16 17#call-to-action button::before { 18 visibility: hidden; 19 position: absolute; 20 content: url('border3.png') url('border3-hover.png') url('border3-active.png'); 21} 22 23#call-to-action button:hover { 24 color: #ffffff; 25 text-shadow: 1px 1px #000000; 26 27 border-image: url('border3-hover.png') 24 24 fill / 24px 24px repeat; 28} 29 30#call-to-action button:active { 31 color: #dddddd; 32 border-image: url('border3-active.png') 24 24 fill / 24px 24px repeat; 33}

That #call-to-action button::before to prevent image loading when hover/clicked causing a very brief flicker... :-X

---
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she

DanielH
Member #934
January 2001
avatar

You can do what I did. I wrapped them up in a function and used flags.

//pseudo code
int init(int flags)
{
    if (!al_init()) return -1
    if (flag & FLAG_IMAGE_ADDON) ...
}

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

The correct code would have been :

for (unsigned int i = list.size() ; i > 0 ; --i) {
   printf("%i\n" , (int)i - 1;
}

It's not often you see underflows, but they're there.

EDIT
Eagle init code (verbatim)

Allegro5System* a5sys = GetAllegro5System();
if (EAGLE_FULL_SETUP != a5sys->Initialize(EAGLE_FULL_SETUP) {
   EagleWarn() << "Not all modules initialized. Warning.\n";
}
EagleGraphicsContext* win = a5sys->CreateGraphicsContext(800,600 , EAGLE_WINDOWED | EAGLE_OPENGL);
if (!(win && win->Valid())) {
   EagleCritical() << "Failed to create window.\n";
}

3 line setup for a window. It serves me right. No more lame queue creation and registration every time you want a window with input. Multiple thread safe windows and more.

Dizzy Egg
Member #10,824
March 2009
avatar

;D....Eagle anyone?....no? well ok then.

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Peter Hull
Member #1,136
March 2001

{"name":"612991","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/8\/88c3874f8b5efb365312ba84dabe7fe5.png","w":462,"h":201,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/8\/88c3874f8b5efb365312ba84dabe7fe5"}612991
From the init code of a microcontroller

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Polybios
Member #12,293
October 2010

Elias said:

Ohhh, can we have al_init_everything()

Then I also want al_destroy_everything()
>:(

Peter Hull
Member #1,136
March 2001

Polybios said:

Then I also want al_destroy_everything()

That exists but only people above our pay-grade are allowed to used it.

Here's a bit of a shocker that I did not know about until today, from man abs

SYNOPSIS
     #include <stdlib.h>

     int
     abs(int i);

DESCRIPTION
     The abs() function computes the absolute value of the integer i.

RETURN VALUES
     The abs() function returns the absolute value.

So far, so good, but then:

BUGS
     The absolute value of the most negative integer remains negative.


:'(

MiquelFire
Member #3,110
January 2003
avatar

That's because signed integers have an extra negative number compared to positive numbers, for example, for an 8 bit value, we have -128 to 127.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Peter Hull
Member #1,136
March 2001

That's because signed integers have an extra negative number compared to positive numbers, for example, for an 8 bit value, we have -128 to 127.

You know this and I know this. But I'm sure I've never written code to account for it

x = abs(x);
if (x >= 0) {
 something(x);
} else {
 error();
}

I don't think there's a better option either, returning zero or INT_MAX or anything else would also lead to silent errors. And C doesn't usually raise a signal for integer arithmetic (? does it?)

MiquelFire
Member #3,110
January 2003
avatar

I'm trying to think if a way in which the negative number issue with abs would matter anyway. With signed 8-bit, if -128 is a possible value, what's stopping you from getting -150 before you call abs? I think the times you need to worry about the minimum number being passed to abs, you have to worry about the value being out of range for the integer type you are using anyway.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Go to: