forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Freeze on a while

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
G-nesh



Joined: 28 May 2008
Posts: 4

PostPosted: Wed May 28, 2008 9:41 am    Post subject: Freeze on a while Reply with quote

Hi guys,

I'm new to this forum, I've just started coding some little programs on my psp slim the cf is 3.90 m33, so the problem is that the psp freeze at a while(1) loop.

Code:

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>

PSP_MODULE_INFO("Hello World", 0, 1, 1);

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common) {
        sceKernelExitGame();
        return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp) {
        int cbid;

        cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
        sceKernelRegisterExitCallback(cbid);

        sceKernelSleepThreadCB();
        return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
        int thid = 0;

        thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
        if(thid >= 0) {
                sceKernelStartThread(thid, 0, 0);
        }

        return thid;
}

int main() {
        pspDebugScreenInit();
        SetupCallbacks();

        int counter = 0;
        int i = 0;
        int c = 0;
        SceCtrlData pad;


        printf("Press [X] To Start the Timer\n");
// Freeze...
        while(1) {
                if(pad.Buttons & PSP_CTRL_CROSS) {
                break;
                }
        }

        while(1) {
                sceCtrlReadBufferPositive(&pad, 1);
                if(pad.Buttons & PSP_CTRL_CIRCLE) {
                        break;
                }
                pspDebugScreenClear();

                printf("Press [O] To Stop the Timer\n");
                printf("Counter: %i", counter);

                counter++;

                for(i=0; i<5; i++) {
                        sceDisplayWaitVblankStart();
                }


        }

        pspDebugScreenClear();
        printf("Counter Finished.");
        printf("Final Count: %i", counter);

        sceKernelSleepThread();

        return 0;
}


I've used a tutorial and just pasted the code, I've tried to understand why it freeze but I can't find a valid answer.

If someone could help it will be really appreciated!
Thanks in advance, and hi to everybody! :D
_________________
Lord of Obstacles
Back to top
View user's profile Send private message
Crux



Joined: 25 May 2008
Posts: 10

PostPosted: Wed May 28, 2008 9:48 am    Post subject: Reply with quote

Put this in the while:

sceCtrlReadBufferPositive(&pad, 1);

What it does is stores the current button pressed in the pad variable. Its not storing anything while its looping, so therefor it will never break the loop.

EDIT: make sure its outside the if statement as well
Back to top
View user's profile Send private message
G-nesh



Joined: 28 May 2008
Posts: 4

PostPosted: Wed May 28, 2008 10:02 am    Post subject: Reply with quote

Thank you Crux!

Hehe I feel so dumb, when I've seen your answer I just go back to the tutorial and... I missed that row...

I'm sorry for the dumb post :)
_________________
Lord of Obstacles
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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