BUG: GP2X & PLATFORMINFO$ = black screen!

Previous topic - Next topic

François Vanzeveren

Hello,

With build 5.235, the PLATFORMINFO$ function generates a freeze on a black screen with the GP2X:
The code below only works when commenting the line with PLATFORMINFO$ (the fourth line of code)...
Code (glbasic) Select
SETSCREEN 320, 240, 0; // Set the screen size (not full screen)
LIMITFPS 60; // Limit to 60 frames per second
ALLOWESCAPE TRUE; // Disable instant Esc function

GLOBAL gDevice$ = PLATFORMINFO$("DEVICE");
//IF gDevice$ = "POCKETPC" OR gDevice$ = "F200"
// SYSTEMPOINTER FALSE; // device with touchscreen!
//ELSE
// SYSTEMPOINTER TRUE; // device without touchscreen --> simulate pen with the mouse!
//ENDIF

LoadMedia(); // Call function to load media files

// Boucle principale.
// Quitter la boucle --> quitter le jeu et revenir au menu GP2X
WHILE TRUE
// Affichage et gestion de l'écran de démarrage
LOCAL touchedMenu, highlightedMenu;
LOCAL isMenuSelected = FALSE, dpad = FALSE, pen = FALSE;

LOADBMP "resources/home.bmp";
DrawHomeMenu(0);
SHOWSCREEN;

WHILE isMenuSelected = FALSE
touchedMenu = GetTouchedHomeMenu();
IF pen = FALSE AND touchedMenu > -1
// L'utilisateur vient tout juste de pointer un menu avec le stylet/la souris
highlightedMenu = touchedMenu;
pen = TRUE
ELSEIF pen = TRUE AND touchedMenu = -1
// L'utilisateur vient de relacher la pression sur un menu avec son stylet.
isMenuSelected = TRUE;
pen = FALSE;
ELSEIF dpad = FALSE AND (KEY(200) OR KEY(208))
IF KEY(200) THEN highlightedMenu = MAX(0, highlightedMenu-1); // up arrow
IF KEY(208) THEN highlightedMenu = MIN(4, highlightedMenu+1); // down arrow
dpad = TRUE;
ELSEIF KEY(200) = 0 AND KEY(208) = 0
dpad = FALSE;
ENDIF
DrawHomeMenu(highlightedMenu);
SHOWSCREEN;

// les boutons 'SELECT' (15) et 'B' (45) provoquent
// la sélection du menu en surbrillance.
IF KEY(45) OR KEY(15) THEN isMenuSelected = TRUE;
// Le bouton 'HOME' (F200) permet de quitter le jeu.
IF KEY(28)
isMenuSelected = TRUE;
highlightedMenu = 4;
ENDIF

WEND

IF highlightedMenu = 4 THEN END // Quit game
WEND

END // End the program

FUNCTION LoadMedia:
LOADANIM "resources/font-15px.png", 0, 15, 15;
LOADANIM "resources/home-menu.png", 1, 180, 30;
LOADANIM "resources/pause-menu.png", 2, 180, 30;
LOADANIM "resources/bombs-20px.png", 10, 20, 20;
ENDFUNCTION

FUNCTION DrawHomeMenu: tSelectedMenu
LOCAL offset;
FOR i = 0 TO 4
offset = 0;
IF tSelectedMenu = i THEN offset = 1;
DRAWANIM 1, 2*i+offset, (320-180)/2, 60+30*i;
NEXT
ENDFUNCTION

FUNCTION DrawPauseMenu: tSelectedMenu
LOCAL offset;
FOR i = 0 TO 1
offset = 0;
IF tSelectedMenu = i THEN offset = 1;
DRAWANIM 1, 2*i+offset, (320-180)/2, 60+30*i;
NEXT
ENDFUNCTION

FUNCTION GetTouchedHomeMenu:
LOCAL retval = -1;
MOUSESTATE mx, my, b1, b2;
IF b1 = 1 // pushed
FOR i = 0 TO 4
IF IsPointInRect(mx,my, (320-180)/2, 60+30*i, 180, 30) THEN retval = i;
NEXT
ENDIF
RETURN retval;
ENDFUNCTION

FUNCTION IsPointInRect: px,py, rx,ry,rw,rh
LOCAL retval = FALSE;
IF px > rx AND px < rx + rw AND py > ry AND py < ry + rh
retval = TRUE;
ENDIF
RETURN retval;
ENDFUNCTION

Ian Price

I came across this a short while ago - Gernot suggests using this instead -

Code (glbasic) Select
GLOBAL info$
info$=PLATFORMINFO$("device")
Rather than
Code (glbasic) Select
Global info$=PLATFORMINFO$("device")It works fine.
I came. I saw. I played.

Moru

Yes, it's in general safer to declare globals and then give them a value on a separate line.

François Vanzeveren

Thanks, I will try this instead.

But it used to work with previous versions...

So let's say it is good practice to declare variable before assigning value ;)

Neurox

Hi,
remove this line :
QuoteSETSCREEN 320, 240, 0;
Setscreen is not necessary for GP2X,
go to "Project-Property" to see the correct resolution.

Neurox
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

Ian Price

Quote from: brainoisThanks, I will try this instead.

But it used to work with previous versions...

So let's say it is good practice to declare variable before assigning value ;)
It did, but now it doesn't. Just use (a version of) what I posted and you'll be alright. :)
I came. I saw. I played.

Kitty Hello

Problem is, assigning a global happens before any initialization occoured. Thus, you call PLATFORMINFO$() before the String class initialized.
GLOBAL state = 15
is perfectly safe and reccomended.