Why does this code hang ?

Hi everyone,

When I run the following code ;

%%%%%%
screen=0;
[wPtr,rect]=Screen('OpenWindow',screen, [], []);
HideCursor;
tic
freq_Hz = 20 ;
secs = 1 / freq_Hz;
measurement_time = 5;
i=1;
t0 = clock;
pwm = zeros(1, 100000);
while etime(clock, t0) < measurement_time
disp(clock);
while etime(clock, t0) < secs
disp(clock);
black=BlackIndex(wPtr);
pwm(i)=0;
i = i +1;
Screen('FillRect',wPtr,black, [0 0 1680 1050]);
Screen(wPtr, 'Flip');
end
while etime(clock, t0) < secs
disp(clock);
white=WhiteIndex(wPtr);
pwm(i)=1;
i = i +1;
Screen('FillRect',wPtr,black);
Screen('FillRect',wPtr,white, [0 0 1680 1050] );
Screen(wPtr, 'Flip');
end
end
Screen('Close', wPtr);
%%%%%%

Screen hangs and becomes nonresponsive.

Any ideas or hints for the problem ?

Thanks!
yes, you're using the worst possible way of stimulus timing, it bruns
all your cpu cycles causing windows to flag your app as
non-responsive.

Read the tutorial pdf that comes with PTB and especially learn about
Screen('Flip')'s when parameter, thats what you should use for timing.

Best,
Dee

On 22/11/2011, Yigit Turgut <y.turgut@...> wrote:
> Hi everyone,
>
> When I run the following code ;
>
> %%%%%%
> screen=0;
> [wPtr,rect]=Screen('OpenWindow',screen, [], []);
> HideCursor;
> tic
> freq_Hz = 20 ;
> secs = 1 / freq_Hz;
> measurement_time = 5;
> i=1;
> t0 = clock;
> pwm = zeros(1, 100000);
> while etime(clock, t0) < measurement_time
> disp(clock);
> while etime(clock, t0) < secs
> disp(clock);
> black=BlackIndex(wPtr);
> pwm(i)=0;
> i = i +1;
> Screen('FillRect',wPtr,black, [0 0 1680 1050]);
> Screen(wPtr, 'Flip');
> end
> while etime(clock, t0) < secs
> disp(clock);
> white=WhiteIndex(wPtr);
> pwm(i)=1;
> i = i +1;
> Screen('FillRect',wPtr,black);
> Screen('FillRect',wPtr,white, [0 0 1680 1050] );
> Screen(wPtr, 'Flip');
> end
> end
> Screen('Close', wPtr);
> %%%%%%
>
> Screen hangs and becomes nonresponsive.
>
> Any ideas or hints for the problem ?
>
> Thanks!
>
In the slides.pdf came with the install ;

Instead of:
Screen('FillRect', win, [red1 green1 blue1], [left1 top1 right1 bot1]);

Write:
mycolors = [red1 green1 blue1; red2 green2 blue2; ... ; redn greenn bluen];
myrects = [left1 top1 right1 bot1; left2 top2 right2 bot2; ... ; leftn topn rightn botn];
Screen('FillRect', win, mycolors, myrects);

And I exactly do this as stated.This is how I use ;

Screen('FillRect',wPtr,black, [0 0 1680 1050])

This is how VBLSynctest uses ;

Screen('FillRect', w, mod(i, 255), [pos+20 pos+20 pos+400 pos+400]);

It draws a rectangle with simple animation and I just blink (on/off) screen yet it gives 1 missed flips out of 600 but my code returns 180 missed flips out of 600.







--- In psychtoolbox@yahoogroups.com, "mauro.toroe" <mauro.toro.e@...> wrote:
>
>
> Greatings Yigit,
>
> Take a look at:
> http://docs.psychtoolbox.org/VBLSyncTest
>
> And "edit VBLSyncTest" to get an idea about how to refresh your stimuli in a real precise way.
>
> Also, try using GetSecs() to get accurate timing meassures, the clock function gives a really weird output, maybe that's what breaking your script.
>
> Suerte!
>
> --- In psychtoolbox@yahoogroups.com, Yigit Turgut <y.turgut@> wrote:
> >
> > Hi everyone,
> >
> > When I run the following code ;
> >
> > %%%%%%
> > screen=0;
> > [wPtr,rect]=Screen('OpenWindow',screen, [], []);
> > HideCursor;
> > tic
> > freq_Hz = 20 ;
> > secs = 1 / freq_Hz;
> > measurement_time = 5;
> > i=1;
> > t0 = clock;
> > pwm = zeros(1, 100000);
> > while etime(clock, t0) < measurement_time
> > disp(clock);
> > while etime(clock, t0) < secs
> > disp(clock);
> > black=BlackIndex(wPtr);
> > pwm(i)=0;
> > i = i +1;
> > Screen('FillRect',wPtr,black, [0 0 1680 1050]);
> > Screen(wPtr, 'Flip');
> > end
> > while etime(clock, t0) < secs
> > disp(clock);
> > white=WhiteIndex(wPtr);
> > pwm(i)=1;
> > i = i +1;
> > Screen('FillRect',wPtr,black);
> > Screen('FillRect',wPtr,white, [0 0 1680 1050] );
> > Screen(wPtr, 'Flip');
> > end
> > end
> > Screen('Close', wPtr);
> > %%%%%%
> >
> > Screen hangs and becomes nonresponsive.
> >
> > Any ideas or hints for the problem ?
> >
> > Thanks!
> >
>