You are not logged in.

#1 2009-06-22 02:00:29

TPAINROXX
Member

[RESOLVED] Image Corruption During Runtime

Hey again. GRRLIB has been working pretty good until I started using GRRLIB_Printf() to display text on the screen. All it's supposed to do is display settings and game score, but the image corrupts a few seconds after displaying. Like the function displays them right and then after about 3 seconds the text just turns into what looks like sand.  After showing the text it also sometimes messes up the program as well (starting a game won't work).

I'll post pictures if anybody needs them.

Thanks for any help,
~BW

Offline

 

#2 2009-06-22 14:45:14

Crayon
Bad Mother Fucker

Re: [RESOLVED] Image Corruption During Runtime

TPAINROXX wrote:

I'll post pictures if anybody needs them.

Hi, I think code would be better wink

Offline

 

#3 2009-06-23 02:16:07

TPAINROXX
Member

Re: [RESOLVED] Image Corruption During Runtime

Thanks for your help, but here's a lot of information.

Problem:

Well now the GRRLIB_Printf works fine, but it messes up the options background.  When my program starts it works fine, and then you go to options and it works fine. Then you can display the score, which works fine, and then it goes to the menu. Then you can repeat that one time. But if you displayed the score twice and open up the options you get messed up options background 1. Then if you try to make it display the score it does the delay (but doesn't display) and then it goes to the menu. Then if you open up options you get messed up options background 2. Then if you make it display the score it works fine and goes to menu. So then it stays that way.

Also if you restart the program it does the same thing as describe above.

So here's the pics and code, and if anything needs to be explained more just let me know.

===============================

Pictures:

What Options Normally Looks Like:
http://i39.tinypic.com/28k7b5w.png

Messed Up Options 1:
http://i40.tinypic.com/24y3ac7.jpg

Messed Up Options 2:
http://i43.tinypic.com/5mjqtx.jpg

===============================

Score Display Code (GRRLIB_Printf):

I removed some of the comments, but that was it. The complete code has it as is.

Code:

int  game_score = 0;  //Actual game score.
int  game_life  = 5;  //Make lives variable depending on difficulty/options.
bool game;              //This either increases your score or decreases your lives based on game performance.
bool game_easy = true;//The easy/hard difficulty variable.

void score()
{    
    GRRLIB_FillScreen(0x0000000F);
    
    GRRLIB_texImg tex_font = GRRLIB_LoadTexture(font);
    GRRLIB_InitTileSet(&tex_font, 16, 16, 32);
    
    GRRLIB_Printf(100, 100, tex_font, 0xFFFFFFFF, 2, "SCORE: %d", game_score );
        
    GRRLIB_Printf(100, 175, tex_font, 0xFFFFFFFF, 2, "LIVES: %d", game_life);
    
    if (game_easy == true)
    {GRRLIB_Printf(100, 250, tex_font, 0xFFFFFFFF, 2, "DIFFICULTY: EASY");}
        
    else if (game_easy == false)
    {GRRLIB_Printf(100, 250, tex_font, 0xFFFFFFFF, 2, "DIFFICULTY: HARD");}
    
    GRRLIB_Render();
    
    usleep(3*1000*1000);
        
    GRRLIB_FillScreen(0xFFFFFFFF);
}

Options Display Code:

Code:

void OPTIONS()
{
/* Locations
First Button:  

X 540-152 = 388
Y 280-76  = 204

Second Button:

X 540-152 = 388
Y 380-76  = 304
*/
  GRRLIB_texImg tex_pointer1   = GRRLIB_LoadTexture(pointer1);

  GRRLIB_texImg tex_options = GRRLIB_LoadTexture(options);
  GRRLIB_texImg tex_button  = GRRLIB_LoadTexture(button);

  while(1)
  {
    WPAD_ScanPads();
    
    if (WPAD_BUTTON_HOME & WPAD_ButtonsDown(0))
    {break;}
    
    else if (WPAD_BUTTON_PLUS & WPAD_ButtonsDown(0))
    {
        score();
        break;
    }
  
    GRRLIB_FillScreen(0xFFFFFFFF);
    
    GRRLIB_DrawImg( 0, 0, tex_options, 0, 1, 1, 0xFFFFFFFF);
    
    if (normal_menu == true)  //Because the normal menu is "Lights Off"
    {GRRLIB_DrawImg( 388, 204, tex_button, 0, 1, 1, 0xFFFFFFFF);}
    
    if (game_easy == false)  //But easy is on and not easy is off.
    {GRRLIB_DrawImg( 388, 304, tex_button, 0, 1, 1, 0xFFFFFFFF);}
    
    WPAD_IR(WPAD_CHAN_0, &ir1);           //For Wiimote 1 IR.
    WPAD_Orientation(WPAD_CHAN_0, &or1);  //For Wiimote 1 orientation.
    
    GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, tex_pointer1, or1.roll, ir1.z, ir1.z, 0xFFFFFFFF);
    
    GRRLIB_Render();
    
    if ( ((ir1.x >= 388) & (ir1.x <= 540)) & ((ir1.y >= 204) & (ir1.y <= 280)) )
    {
        rumble(0);
    
        WPAD_ScanPads();
        
        if (WPAD_BUTTON_A & WPAD_ButtonsDown(0))
        {
            if (normal_menu == true)
            {normal_menu = false;}
            
            else if (normal_menu == false)
            {normal_menu = true;}
        }
    
    }
    
    else if ( ((ir1.x >= 388) & (ir1.x <= 540)) & ((ir1.y >= 304) & (ir1.y <= 380)) )
    {
        rumble(0);
    
        WPAD_ScanPads();
        
        if (WPAD_BUTTON_A & WPAD_ButtonsDown(0))
        {
            if (game_easy == true)
            {
                game_easy = false;
                game_life = 3;
            }
            
            else if (game_easy == false)
            {
                game_easy = true;
                game_life = 5;
            }
        }
    }
    
    else
    {do_rumble = true;}
    
  }
    
}

Complete Code:

Code:

/*=========================================================
WARNING: Working file; be carful with editing.

WiiMoveIt - By: Brandon Whitmire

Thanks to GRRLIB, and NoNameNo and Crayon for GRRLIB help.
//=========================================================
GRRLIB Download and Help Forum : http://grrlib.santo.fr
*///=======================================================
//     START FILE INCLUSION
//---------------------------------------------------------
//     Important Files & Headers
//---------------------------------------------------------
#include "GRRLIB/GRRLIB/GRRLIB.h"
#include <cstdlib>
#include <time.h>     //For time comparison.
#include <unistd.h>  //For usleep();
#include <wiiuse/wpad.h>
#include <iostream>
using namespace std;

//---------------------------------------------------------
//     Start All File Inclusion
//---------------------------------------------------------

#include "gfx/intro.h"
#include "fonts/font.h"

//---------------------------------------------------------
//     For Regular Menu (aka "Lights Off")
//---------------------------------------------------------

#include "gfx/pointer1.h"

#include "gfx/menu_pix/menu.h"

#include "gfx/menu_pix/button1.h"
#include "gfx/menu_pix/button2.h"
#include "gfx/menu_pix/button3.h"

//---------------------------------------------------------
//     For Inverted Menu (aka "Lights On")
//---------------------------------------------------------

#include "gfx/pointer1_i.h"

#include "gfx/menu_pix/menu_i/menu_i.h"

#include "gfx/menu_pix/menu_i/button1_i.h"
#include "gfx/menu_pix/menu_i/button2_i.h"
#include "gfx/menu_pix/menu_i/button3_i.h"

//---------------------------------------------------------
//     Options
//---------------------------------------------------------

#include "gfx/menu_pix/options/options.h"
#include "gfx/menu_pix/options/button.h"

//---------------------------------------------------------
//     START GAME FILE INCLUSION BELOW
//---------------------------------------------------------

//For All Games 
       #include "games/All/Game_Lose.h"
       #include "games/All/Game_Win.h"

//Game 1 - Tunnel
       #include "games/Game 1 - Tunnel/game1_play.h"
       #include "games/Game 1 - Tunnel/game1_start.h"
       #include "games/Game 1 - Tunnel/thing.h"
       
//Game 2 - Target
       #include "games/Game 2 - Target/bkgd2.h"
       #include "games/Game 2 - Target/target.h"
       #include "games/Game 2 - Target/crosshair.h"
       
//Game 3 - BKW
       #include "games/Game 3 - BKW/bkgd3.h"
       #include "games/Game 3 - BKW/BKW1.h"
       #include "games/Game 3 - BKW/BKW2.h"
       
//Game 4 - SpaceTravel
       #include "games/Game 4 - SpaceTravel/Space4.h"
       #include "games/Game 4 - SpaceTravel/Spaceship.h"

//---------------------------------------------------------
//     END OF FILE INCLUSION
//---------------------------------------------------------
///////////////////////////////////////////////////////////
//---------------------------------------------------------
//     Rumble for IR Pointer Going Over a Button
//---------------------------------------------------------

bool do_rumble = true;  //This is so the Wiimote only rumbles one time if it's on a button.

void rumble(u32 remote_channel)
{
    if (do_rumble == true)
    {
        int rumble_on = 1, rumble_off = 0;

        WPAD_Rumble(remote_channel, rumble_on);
    
        usleep((.5*1000*100));  ///This is in microseconds so 1,000,000 microseconds = 1 second.
    
        WPAD_Rumble (remote_channel, rumble_off);
        
        do_rumble = false;
    }
}

//---------------------------------------------------------
//     Pause Function (Waits for Button to be Hit)
//---------------------------------------------------------

void pausemii(u32 remote_channel)
{
    while(1)
    {
        WPAD_ScanPads();
        
        if (WPAD_ButtonsDown(remote_channel))
        {break;}
    }
}

//---------------------------------------------------------
//     Important Variables and Functions
//---------------------------------------------------------

Mtx GXmodelView2D;  //Needed for GRRLIB

    //Wiimote 1
ir_t ir1;  //IR Movement
    
orient_t or1;  //Orientation Movement

time_t start_time, cur_time;

bool normal_menu  = true; //If true then the it will be "Lights Off" for the menu.

//---------------------------------------------------------
//     Game and Score Functions and Variables
//---------------------------------------------------------

const int  GAME_NUM = 1;       //Number of [WORKING] games.
const bool WIN         = true;  //A constant to help with "Win/Lose Game" instead of "True/False Game".
const bool LOSE     = false; // "ditto"

int  game_score = 0;  //Actual game score.
int  game_life  = 5;  //Make lives variable depending on difficulty/options.
bool game;              //This either increases your score or decreases your lives based on game performance.
bool game_easy = true;//The easy/hard difficulty variable.

void score()
{    
/*
THIS IS GOOD IF YOU ARE NOT FAMILIAR WITH printf AND RELATED.
NORMALLY, I USE cout AND cin INSTEAD OF printf AND scanf.

EXCERPTED FROM DEV-CPP HELP ON INPUT/OUTPUT IN C.

The % Format Specifiers:

The % specifiers that you can use in ANSI C are: 

      Usual variable type           Display

%c        char                     single character
%d (%i)   int                      signed integer
%e (%E)   float or double          exponential format
%f        float or double          signed decimal
%g (%G)   float or double          use %f or %e as required
%o        int                      unsigned octal value

%p        pointer                  address stored in pointer
%s        array of char            sequence of characters
%u        int                      unsigned decimal
%x (%X)   int                      unsigned hex value
*/
/*    if (game_life <= 0)
    {
        GRRLIB_texImg tex_Game_Over = GRRLIB_LoadTexture(Game_Over);
        
        GRRLIB_FillScreen(0x0000000F);
        
        GRRLIB_DrawImg( 0, 0, tex_Game_Over, 0, 1, 1, 0xFFFFFFFF);  //64x 52y
    }
*/
    GRRLIB_FillScreen(0x0000000F);
    
    GRRLIB_texImg tex_font = GRRLIB_LoadTexture(font);
    GRRLIB_InitTileSet(&tex_font, 16, 16, 32);
    
    GRRLIB_Printf(100, 100, tex_font, 0xFFFFFFFF, 2, "SCORE: %d", game_score );
        
    GRRLIB_Printf(100, 175, tex_font, 0xFFFFFFFF, 2, "LIVES: %d", game_life);
    
    if (game_easy == true)
    {GRRLIB_Printf(100, 250, tex_font, 0xFFFFFFFF, 2, "DIFFICULTY: EASY");}
        
    else if (game_easy == false)
    {GRRLIB_Printf(100, 250, tex_font, 0xFFFFFFFF, 2, "DIFFICULTY: HARD");}
    
    GRRLIB_Render();
    
    usleep(3*1000*1000);
        
    GRRLIB_FillScreen(0xFFFFFFFF);
}

//---------------------------------------------------------
//     Options Function
//---------------------------------------------------------

void OPTIONS()
{
/* Locations
First Button:  

X 540-152 = 388
Y 280-76  = 204

Second Button:

X 540-152 = 388
Y 380-76  = 304
*/
  GRRLIB_texImg tex_pointer1   = GRRLIB_LoadTexture(pointer1);

  GRRLIB_texImg tex_options = GRRLIB_LoadTexture(options);
  GRRLIB_texImg tex_button  = GRRLIB_LoadTexture(button);

  while(1)
  {
    WPAD_ScanPads();
    
    if (WPAD_BUTTON_HOME & WPAD_ButtonsDown(0))
    {break;}
    
    else if (WPAD_BUTTON_PLUS & WPAD_ButtonsDown(0))
    {
        score();
        break;
    }
  
    GRRLIB_FillScreen(0xFFFFFFFF);
    
    GRRLIB_DrawImg( 0, 0, tex_options, 0, 1, 1, 0xFFFFFFFF);
    
    if (normal_menu == true)  //Because the normal menu is "Lights Off"
    {GRRLIB_DrawImg( 388, 204, tex_button, 0, 1, 1, 0xFFFFFFFF);}
    
    if (game_easy == false)  //But easy is on and not easy is off.
    {GRRLIB_DrawImg( 388, 304, tex_button, 0, 1, 1, 0xFFFFFFFF);}
    
    WPAD_IR(WPAD_CHAN_0, &ir1);           //For Wiimote 1 IR.
    WPAD_Orientation(WPAD_CHAN_0, &or1);  //For Wiimote 1 orientation.
    
    GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, tex_pointer1, or1.roll, ir1.z, ir1.z, 0xFFFFFFFF);
    
    GRRLIB_Render();
    
    if ( ((ir1.x >= 388) & (ir1.x <= 540)) & ((ir1.y >= 204) & (ir1.y <= 280)) )
    {
        rumble(0);
    
        WPAD_ScanPads();
        
        if (WPAD_BUTTON_A & WPAD_ButtonsDown(0))
        {
            if (normal_menu == true)
            {normal_menu = false;}
            
            else if (normal_menu == false)
            {normal_menu = true;}
        }
    
    }
    
    else if ( ((ir1.x >= 388) & (ir1.x <= 540)) & ((ir1.y >= 304) & (ir1.y <= 380)) )
    {
        rumble(0);
    
        WPAD_ScanPads();
        
        if (WPAD_BUTTON_A & WPAD_ButtonsDown(0))
        {
            if (game_easy == true)
            {
                game_easy = false;
                game_life = 3;
            }
            
            else if (game_easy == false)
            {
                game_easy = true;
                game_life = 5;
            }
        }
    }
    
    else
    {do_rumble = true;}
    
  }
    
}

//---------------------------------------------------------
//     Edited Options Func. for START GAME
//---------------------------------------------------------

void GAME()
{
    GRRLIB_texImg tex_thing  = GRRLIB_LoadTexture(thing);
    
    while(1)
    {
        GRRLIB_FillScreen(0xFFFFFFFF);
    
        GRRLIB_DrawImg ( ir1.x - 32, ir1.y - 26, tex_thing, or1.roll, ir1.z, ir1.z, 0xFFFFFFFF);
    }
}

//---------------------------------------------------------
//     Intro/Credits Function
//---------------------------------------------------------

void play_intro()
{
    GRRLIB_texImg tex_intro = GRRLIB_LoadTexture(intro);
    
    time(&start_time);
    
    while(1)
    {
        GRRLIB_FillScreen(0xFFFFFFFF);
    
        GRRLIB_DrawImg( 0, 0, tex_intro, 0, 1, 1, 0xFFFFFFFF);
    
        GRRLIB_Render();
        
        WPAD_ScanPads();
    
        if ( (WPAD_ButtonsDown(0) & WPAD_BUTTON_HOME)  )
        {break;}
        
        else if ( (cur_time - start_time) > 5)
        {break;}
    }
    
    GRRLIB_FillScreen(0xFFFFFFFF);
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
////-------------------------------------------------------////
////     Main Program                                      ////
////-------------------------------------------------------////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////

int main() 
{
    GRRLIB_texImg tex_pointer1   = GRRLIB_LoadTexture(pointer1);
    
    GRRLIB_texImg tex_menu      = GRRLIB_LoadTexture(menu);
    
    GRRLIB_texImg tex_button1    = GRRLIB_LoadTexture(button1);
    GRRLIB_texImg tex_button2   = GRRLIB_LoadTexture(button2);
    GRRLIB_texImg tex_button3   = GRRLIB_LoadTexture(button3);
        
    GRRLIB_texImg tex_pointer1_i = GRRLIB_LoadTexture(pointer1_i);
    
    GRRLIB_texImg tex_menu_i     = GRRLIB_LoadTexture(menu_i);
    
    GRRLIB_texImg tex_button1_i  = GRRLIB_LoadTexture(button1_i);
    GRRLIB_texImg tex_button2_i  = GRRLIB_LoadTexture(button2_i);
    GRRLIB_texImg tex_button3_i  = GRRLIB_LoadTexture(button3_i);
    
    GRRLIB_Init();  //Starts GRRLIB
    
    WPAD_Init();  //Start WPAD-related Functions
    
    WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR);
        
    WPAD_SetVRes(WPAD_CHAN_0, 640, 480);

    cout<<"ir1.x: "<<ir1.x<<"/tir1.y: "<<ir1.y<<"\n";  
    
    play_intro();  //Plays intro/credits

    
while(1) 
    {    
//***********MENU START******************************************************************************
        if (normal_menu == true)
        {GRRLIB_DrawImg( 0, 0, tex_menu, 0, 1, 1, 0xFFFFFFFF);}
        
        else if (normal_menu == false)
        {GRRLIB_DrawImg( 0, 0, tex_menu_i, 0, 1, 1, 0xFFFFFFFF);}
        
        WPAD_IR(WPAD_CHAN_0, &ir1);           //For Wiimote 1 IR.
        WPAD_Orientation(WPAD_CHAN_0, &or1);  //For Wiimote 1 orientation.
    
        if (normal_menu == true)
        {GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, tex_pointer1, or1.roll, ir1.z, ir1.z, 0xFFFFFFFF);}
        
        else if (normal_menu == false)
        {GRRLIB_DrawImg(ir1.x - 48, ir1.y - 45, tex_pointer1_i, or1.roll, ir1.z, ir1.z, 0xFFFFFFFF);}
     
        GRRLIB_Render();
        
        WPAD_ScanPads();
        
//***********START***********************************************************************************    
        if ( ( (ir1.x >= 20) & (ir1.x <= 212) & ( (ir1.y >= 364) & (ir1.y <= 620) ) ) )
        {
            rumble(0);
            
            if (normal_menu == true)
            {GRRLIB_DrawImg(0, 0, tex_button1, 0, 1, 1, 0xFFFFFFFF);}
            
            else if (normal_menu == false)
            {GRRLIB_DrawImg(0, 0, tex_button1_i, 0, 1, 1, 0xFFFFFFFF);}
            
            GRRLIB_Render();
            
            WPAD_ScanPads();
            
            if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
            {GAME();}
        }   
//************OPTIONS********************************************************************************        
        else if ( ( (ir1.x >= 225) & (ir1.x <= 417) ) & ( (ir1.y >= 364) & (ir1.y <= 620) ) )
        {
            rumble(0);
        
            if (normal_menu == true)
            {GRRLIB_DrawImg(0, 0, tex_button2, 0, 1, 1, 0xFFFFFFFF);}
            
            else if (normal_menu == false)
            {GRRLIB_DrawImg(0, 0, tex_button2_i, 0, 1, 1, 0xFFFFFFFF);}
            
            GRRLIB_Render();
            
            WPAD_ScanPads();
            
            if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
            {OPTIONS();}
        }  

//************EXIT***********************************************************************************    
        else if ( ( (ir1.x >= 428) & (ir1.x <= 620) ) & ( (ir1.y >= 364) & (ir1.y <= 620) ) )
        {
            rumble(0);
        
            if (normal_menu == true)
            {GRRLIB_DrawImg(0, 0, tex_button3, 0, 1, 1, 0xFFFFFFFF);}
            
            else if (normal_menu == false)
            {GRRLIB_DrawImg(0, 0, tex_button3_i, 0, 1, 1, 0xFFFFFFFF);}
            
            GRRLIB_Render();
            
            WPAD_ScanPads();
            
            if(WPAD_ButtonsHeld(0) & WPAD_BUTTON_A)
            {goto exit;}
        }  
//************FOR RUMBLE*****************************************************************************
        else 
        {do_rumble = true;}
//***********END LOOP }******************************************************************************
        GRRLIB_FillScreen(0xFFFFFFFF);
}    
//***********END*************************************************************************************
    exit:             //This is just in case I add anything after the loop, then it will exit correctly.

    GRRLIB_Exit();  // Be a good boy, clear the memory allocated by GRRLIB
    
    return 0;
}

//---------------------------------------------------------
//     End of Program
//---------------------------------------------------------

Last edited by TPAINROXX (2009-06-23 02:17:17)

Offline

 

#4 2009-06-25 09:32:26

JustWoody
Member

Re: [RESOLVED] Image Corruption During Runtime

I had this same problem with Mahjongg and ended up only creating textures for the scenes / menus as i needed them and freeing them up when moving between menus or scenes

I've not looked at your code, but if I were you I would check for any other possible memory leaks as this was partially responsible for the problems I was seeing too

Last edited by JustWoody (2009-06-25 09:34:19)

Offline

 

#5 2009-06-25 18:10:23

Crayon
Bad Mother Fucker

Re: [RESOLVED] Image Corruption During Runtime

Hi, in your score() function you keep allocating memory, so each iteration by calling GRRLIB_LoadTexture you do a malloc. tex_font is never freed from memory, so after GRRLIB_Render(); put:

Code:

GRRLIB_FreeTexture(tex_font);

Offline

 

#6 2009-06-26 13:55:04

JustWoody
Member

Re: [RESOLVED] Image Corruption During Runtime

I was just looking at the while loop of your main function and there seems to be some pretty crazy things going on in it.

So if you don't mind I thought I could give you some advice to clean it up? The main things that stand out for me are:

Why are there multiple renders and scan pads? The best bet is to do a scan of the pads at the top of your loop and then a render at the end (making sure that you display your cursor last just before the render) - (unless you are trying to get a particular effect that I am not seeing)

You do a rumble(0) in each of the conditional (if) statements, this means that you are always doing this so do this just once outside of the conditional logic

There is also a lot of cases where you do something like this:

Code:

            if (normal_menu == true)
            {GRRLIB_DrawImg(0, 0, tex_button2, 0, 1, 1, 0xFFFFFFFF);}
            
            else if (normal_menu == false)
            {GRRLIB_DrawImg(0, 0, tex_button2_i, 0, 1, 1, 0xFFFFFFFF);}

As normal_menu is a boolean then you can be sure that if its not true it has to be false so don't need to check for this, also you can use the ? : operators so it would look something like this:

Code:

            GRRLIB_DrawImg(0, 0, normal_menu==true ? tex_button2 : tex_button2_i, 0, 1, 1, 0xFFFFFFFF);

I hope this helps + sorry if this comes across as interfering

Offline

 

#7 2009-06-26 18:14:52

TPAINROXX
Member

Re: [RESOLVED] Image Corruption During Runtime

Thanks Crayon and JustWoody, I appreciate any help, and I've been cleaning up the code a little. I know the code is a little less than decent, but I want to get the game demo working and then clean up the code (but thanks for the hint on the ? operator (I forgot about because I never use it)).

The code's rather a mess now, but hopefully someday it be as beautiful as a golden-laced marble statue...

Code:

[Insert More Rambling]

Last edited by TPAINROXX (2009-06-26 18:18:05)

Offline

 

#8 2009-06-26 18:59:45

Crayon
Bad Mother Fucker

Re: [RESOLVED] Image Corruption During Runtime

Hey, I have a few words to say on the rumble function.

First, this code allocate memory each time is't called for nothing:

Code:

int rumble_on = 1, rumble_off = 0;

Use #define instead:

Code:

#define rumble_on   1
#define rumble_off  0

Secondly, when you know the result of a calculation, don't let the processor do it. When it's in a loop it takes time for nothing.

Code:

        usleep((.5*1000*100));  ///This is in microseconds so 1,000,000 microseconds = 1 second.

Should be:

Code:

        usleep(50000);  ///This is in microseconds so 1,000,000 microseconds = 1 second. Result is (.5*1000*100)

I have done some code for rumbling if you are interested. Check this:
http://grrlib.santo.fr/forum/viewtopic.php?pid=731#p731

Offline

 

#9 2009-06-26 19:31:37

TPAINROXX
Member

Re: [RESOLVED] Image Corruption During Runtime

Thanks again for the optimization help. I'll take a look at the rumble code as well. My C/C++ isn't the best in the world, but much thanks.

Also, I have a non-related issue between GRRLIB versions. The SVN version (rev101) is giving me errors:

Code:

 "make" 
main.cpp
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp: In function 'void score()':
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:195: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:198: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_Printf(f32, f32, GRRLIB_texImg*, u32, f32, const char*, ...)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:200: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_Printf(f32, f32, GRRLIB_texImg*, u32, f32, const char*, ...)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:202: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_Printf(f32, f32, GRRLIB_texImg*, u32, f32, const char*, ...)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp: In function 'void GAME()':
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:220: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:221: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:222: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:242: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:243: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:244: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:248: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:276: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:290: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:301: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp: In function 'void OPTIONS()':
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:330: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:332: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:333: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:350: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:353: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:356: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:361: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp: In function 'void play_intro()':
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:417: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:421: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp: In function 'int main()':
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:440: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:442: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:444: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:445: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:446: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:448: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:450: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:452: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:453: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:454: error: conversion from 'GRRLIB_texImg*' to non-scalar type 'GRRLIB_texImg' requested
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:473: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:476: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:482: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:485: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:495: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:498: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:513: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:516: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:532: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
c:/DevkitPro/examples/wii/grrlib/examples/WiiMoveIt/source/main.cpp:535: error: cannot convert 'GRRLIB_texImg' to 'GRRLIB_texImg*' for argument '3' to 'void GRRLIB_DrawImg(f32, f32, GRRLIB_texImg*, float, float, f32, u32)'
make[1]: *** [main.o] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:35

But the GRRLIB 4.0.0 release version isn't giving me these problems. I'm using the release version now, but I just wanted to see if you know anything about the rev101 errors (or if I should even be using rev101...). My code is the about the same as you've seen above.

Last edited by TPAINROXX (2009-06-26 19:37:54)

Offline

 

#10 2009-06-26 20:08:56

Crayon
Bad Mother Fucker

Re: [RESOLVED] Image Corruption During Runtime

In the svn version GRRLIB is using pointer to texture image.

Ex:
GRRLIB_texImg *tex_Game_Over = GRRLIB_LoadTexture(Game_Over);

Check lesson1 for examples:
http://code.google.com/p/grrlib/source/ … rce/main.c

Offline

 

#11 2009-07-01 00:14:17

Crayon
Bad Mother Fucker

Re: [RESOLVED] Image Corruption During Runtime

I have another small hint, when you are checking a boolean you could simply use if/else. There is no need for a else if, the second choice is always the opposite of the first one:

Code:

            if (game_easy == true)
            {
                game_easy = false;
                game_life = 3;
            }
 
            else if (game_easy == false) // Problem is here
            {
                game_easy = true;
                game_life = 5;
            }

By doing so, you will save one call to the CPU wink

Another thing, srand does not need to be in a loop. Call it once: http://msdn.microsoft.com/en-us/library … S.71).aspx

Finally (for now), instead of this:

Code:

    for (int game_count = 1; game_count <= GAME_NUM; game_count++)  //This is to keep track of which games have been played
    {game_played[game_count - 1] = false;}  //in a session.

I would use this (you save one operation by iteration):

Code:

    for (int game_count = 0; game_count < GAME_NUM; game_count++)  //This is to keep track of which games have been played
    {game_played[game_count] = false;}  //in a session.

Even better woulder be to use a memset: http://msdn.microsoft.com/en-us/library … S.60).aspx

Offline

 

#12 2009-07-07 05:39:54

TPAINROXX
Member

Re: [RESOLVED] Image Corruption During Runtime

I'll start implementing it tomorrow (as I've been on vacation a few days...), but thanks Crayon once again!

Offline

 

Board footer

Powered by FluxBB