Freeze on a while

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
G-nesh
Posts: 4
Joined: Wed May 28, 2008 8:21 am

Freeze on a while

Post by G-nesh »

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: Select all

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

PSP_MODULE_INFO&#40;"Hello World", 0, 1, 1&#41;;

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
        sceKernelExitGame&#40;&#41;;
        return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
        int cbid;

        cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
        sceKernelRegisterExitCallback&#40;cbid&#41;;

        sceKernelSleepThreadCB&#40;&#41;;
        return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
        int thid = 0;

        thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
        if&#40;thid >= 0&#41; &#123;
                sceKernelStartThread&#40;thid, 0, 0&#41;;
        &#125;

        return thid;
&#125;

int main&#40;&#41; &#123;
        pspDebugScreenInit&#40;&#41;;
        SetupCallbacks&#40;&#41;;

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


        printf&#40;"Press &#91;X&#93; To Start the Timer\n"&#41;;
// Freeze...
        while&#40;1&#41; &#123;
                if&#40;pad.Buttons & PSP_CTRL_CROSS&#41; &#123;
                break;
                &#125;
        &#125;

        while&#40;1&#41; &#123;
                sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
                if&#40;pad.Buttons & PSP_CTRL_CIRCLE&#41; &#123;
                        break;
                &#125;
                pspDebugScreenClear&#40;&#41;;

                printf&#40;"Press &#91;O&#93; To Stop the Timer\n"&#41;;
                printf&#40;"Counter&#58; %i", counter&#41;;

                counter++;

                for&#40;i=0; i<5; i++&#41; &#123;
                        sceDisplayWaitVblankStart&#40;&#41;;
                &#125;


        &#125;

        pspDebugScreenClear&#40;&#41;;
        printf&#40;"Counter Finished."&#41;;
        printf&#40;"Final Count&#58; %i", counter&#41;;

        sceKernelSleepThread&#40;&#41;;

        return 0;
&#125;
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
Crux
Posts: 10
Joined: Sun May 25, 2008 1:46 pm

Post by Crux »

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
G-nesh
Posts: 4
Joined: Wed May 28, 2008 8:21 am

Post by G-nesh »

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
Post Reply