 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
plebihan
Joined: 16 Jul 2006 Posts: 10
|
Posted: Fri Feb 06, 2009 6:37 am Post subject: I need help for gfx management |
|
|
Hi all,
i'm coding a new version of my HB , Picoozir, and i would like to add some gfx features. Here is a piece of code that allows to select a chopper with the left and right arrows, the next chopper scrolls on the screen. I dont know why but it works 5 or 6 times and the PSP crashs. I tried with SDL and with PSPGU/Grpahics.h but it's the same . I think i got memory management troubles . Could someone help me to handle an understand the gfx secret :)
Here are my 2 functions :
| Code: |
void Scrolling_Helico(char Sens[10], int num_helico)
{
int heli_precedent;
int i=0;
Image *backgin;
Image *backgheli;
char Path_Heli_In[100];
backgheli = loadImage("Images/fond_heli.png");
clearScreen(0x000000);
blitImageToScreen(0,0,480,272,backgheli,0,0);
if (Sens=="Gauche")
{
heli_precedent=num_helico+1;
blitAlphaImageToScreen(0,0,480,272,fleche_gauche_enfoncee,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite,0,0);
flipScreen();
}
if (Sens=="Droite")
{
heli_precedent=num_helico-1;
blitAlphaImageToScreen(0,0,480,272,fleche_gauche,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite_enfoncee,0,0);
flipScreen();
}
sprintf(Path_Heli_In,"Images/select_%d.png",num_helico);
backgin = loadImage(Path_Heli_In);
if (Sens == "Droite")
{
for (i=0;i<400;i=i+30)
{
blitImageToScreen(0,0,480,272,backgheli,0,0);
blitAlphaImageToScreen(480-i,0,i,272,backgin,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_gauche,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite_enfoncee,0,0);
sceDisplayWaitVblankStart();
flipScreen();
}
for (i=400;i<480;i=i+5)
{
blitImageToScreen(0,0,480,272,backgheli,0,0);
blitAlphaImageToScreen(480-i,0,i,272,backgin,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_gauche,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite_enfoncee,0,0);
sceDisplayWaitVblankStart();
flipScreen();
}
}
if (Sens == "Gauche")
{
for (i=0;i<400;i=i+30)
{
blitImageToScreen(0,0,480,272,backgheli,0,0);
blitAlphaImageToScreen(0,0,i,272,backgin,480-i,0);
blitAlphaImageToScreen(0,0,480,272,fleche_gauche_enfoncee,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite,0,0);
sceDisplayWaitVblankStart();
flipScreen();
}
for (i=400;i<480;i=i+5)
{
blitImageToScreen(0,0,480,272,backgheli,0,0);
blitAlphaImageToScreen(0,0,i,272,backgin,480-i,0);
blitAlphaImageToScreen(0,0,480,272,fleche_gauche_enfoncee,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite,0,0);
sceDisplayWaitVblankStart();
flipScreen();
}
}
}
void Choix_Helico()
{
int num_helico=1;
char Path_Heli_Transp[100];
bool redessiner=true;
Image *fond;
Image *heli_transp;
fond = loadImage("Images/fond_heli.png");
heli_transp = loadImage("Images/select_1.png");
while (1)
{
blitImageToScreen(0,0,480,272,fond,0,0);
blitAlphaImageToScreen(0,0,480,272,heli_transp,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_gauche,0,0);
blitAlphaImageToScreen(0,0,480,272,fleche_droite,0,0);
//guStart();
//if (Langue==1)
// {
// intraFontPrint(ltn1, 140, 17, "Bienvenue dans PicoozIR");
// intraFontPrint(ltn1, 360, 260, "By Pacopad");
// }
// if (Langue==2)
// {
// intraFontPrint(ltn1, 140, 17, "Welcome in PicoozIR");
// intraFontPrint(ltn1, 360, 260, "By Pacopad");
// }
//sceGuFinish();
//sceGuSync(0,0);
sceDisplayWaitVblankStart();
flipScreen();
u32 buttons;
while ((buttons = PollButtons(NULL)) == 0)
sceDisplayWaitVblankStart();
if (buttons & PSP_CTRL_SELECT)
break;
if (buttons & PSP_CTRL_TRIANGLE)
{
Pilotage_Picooz();
// Recharge_Fond(num_helico);
}
if (buttons & PSP_CTRL_CROSS)
{
switch (num_helico)
{
case 1:
Pilotage_Picooz();
break;
case 2:
Pilotage_Picooz_Sky();
break;
case 3:
Pilotage_Atlas();
break;
case 4:
Pilotage_Tandem();
break;
case 5:
Pilotage_Fairy();
break;
}
redessiner=true;
}
if (buttons & PSP_CTRL_SQUARE)
{
// Pilotage_Picooz_MX();
//Recharge_Fond(num_helico);
}
if (buttons & PSP_CTRL_CIRCLE)
{
// Pilotage_Picooz_Sky();
//Recharge_Fond(num_helico);
}
if (buttons & PSP_CTRL_LEFT)
{
if (num_helico>1)
{
num_helico--;
Scrolling_Helico("Gauche",num_helico);
}
sprintf(Path_Heli_Transp,"Images/select_%d.png",num_helico);
heli_transp=loadImage(Path_Heli_Transp);
}
if (buttons & PSP_CTRL_RIGHT)
{
if (num_helico<4)
{
num_helico++;
Scrolling_Helico("Droite",num_helico);
}
sprintf(Path_Heli_Transp,"Images/select_%d.png",num_helico);
heli_transp=loadImage(Path_Heli_Transp);
}
}
}
| [/quote] |
|
| Back to top |
|
 |
bkc

Joined: 20 May 2008 Posts: 20 Location: Sweden
|
Posted: Sun Feb 22, 2009 4:40 am Post subject: |
|
|
Because you run out of memory :-)
you load the image over and over again without freeing it :-)
Try
| Code: |
freeImage(fond);
freeImage(heli_transp);
|
at the end of Choix_Helico()
That should work :-) _________________ I only speak these languages:
- C / C + +
- ASM
- Python
- (x)HTML
- PHP
- CSS
- SQL
- JavaScript
|
|
| Back to top |
|
 |
plebihan
Joined: 16 Jul 2006 Posts: 10
|
Posted: Sun Mar 01, 2009 5:08 am Post subject: |
|
|
Thank you, i'll found the matter and i got a memory probelm.
i'm porting my app with oslib and i try to correct all the gfx part
Pacopad |
|
| Back to top |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sun Mar 01, 2009 8:01 am Post subject: |
|
|
| Code: |
char Sens[10];
...
if (Sens == "Droite")
|
This is not how you compare strings in C. You use strcmp. It's probably working only because your compiler is making all the instances of "Droit' point to the same constant string, but you shouldn't rely on that.
Jim _________________ http://www.dbfinteractive.com |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Sun Mar 01, 2009 2:55 pm Post subject: |
|
|
| You should make a generic menu "engine" instead of hard coding it for your particular game. |
|
| Back to top |
|
 |
plebihan
Joined: 16 Jul 2006 Posts: 10
|
Posted: Sun Mar 01, 2009 5:47 pm Post subject: |
|
|
Thank you for your advices guys. It's my first dev on psp and my firt experience in C language.
@Torch: Each chopper has particularity, so to let the code readable , i cant , for the momoent, create a global engine fonction.
@JIM: Thanx , il'll replace all string test i do with strcmp
Cheers
Pacopad |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Sun Mar 01, 2009 10:40 pm Post subject: |
|
|
| Jim wrote: | | Code: |
char Sens[10];
...
if (Sens == "Droite")
|
This is not how you compare strings in C. You use strcmp. It's probably working only because your compiler is making all the instances of "Droit' point to the same constant string, but you shouldn't rely on that.
Jim |
Or you may have global constant zero strings :
| Code: |
constants.h:
extern char const * const C_GAUCHE; // Left
extern char const * const C_DROITE; // Right
constants.c:
char const * const C_GAUCHE = "Gauche";
char const * const C_DROITE = "Droite";
your c files:
#include "constants.h"
...
if (Sens == C_GAUCHE) ...
|
this way this is faster than a strcmp (just an integer comparison).
Of course, a simple enum can work too if a string is not necessary :
| Code: |
enum SensEnumeration { Gauche, Droite };
|
EDIT:
this line seems to be wrong for me :
void Scrolling_Helico(char Sens[10], int num_helico)
it should be :
void Scrolling_Helico(char const * const Sens, int num_helico)
or :
void Scrolling_Helico(SensEnumeration Sens, int num_helico)
or :
void Scrolling_Helico(int Sens, int num_helico) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|