JR Meyer
JR Meyer

Reputation: 232

MATLAB has encountered an internal error and needs to close

I've just installed the new MATLAB R2013b for 64bit Mac, and my OS is OS X 10.8.4. I'm running into a consistent problem that I never had with R2013a. When I run one of my scripts (see below), the entire script goes through OK, but then I keep getting an error message "MATLAB has encountered an internal problem and needs to close." Then I have to shut MATLAB down.

I have a feeling that I've goofed somewhere on the installation since I'm new to MATLAB, but I'm not sure.

This exact same script still runs fine on R2013a, which I've yet to uninstall. The script (making use of Psychtoolbox) is an experiment which opens a screen, presents some text, presents an audio file, and requires the participant to respond with 6 keystrokes. This script only presents two audio files, since I'm just testing it.

All the loops seem to work on both versions of MATLAB, and the screen closes at the end (which only happens after 2 passes through the main loop). I take this to mean the script is working, but something in a post stage is causing issues.

Any and all ideas are much appreciated!

-Josh

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%  SCREEN & AUDIO SETUP %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%
%% SCREEN %%
%%%%%%%%%%%%

% Set up a nice blank screen.
whichScreen = 0;

% Full Screen mode
%window = Screen(whichScreen, 'OpenWindow');

% Small screen mode used for code testing
window = Screen('OpenWindow',0, [450 450 500], [5,5, 550,550]);

white = WhiteIndex(window); % pixel value for white
Screen(window, 'FillRect', white);
Screen(window, 'Flip');

% Set global text size for the display.
Screen('TextSize', window, 15);
Screen(window,'TextFont','Arial');
Screen('TextStyle', window, 0)


%%%%%%%%%%%
%% AUDIO %%
%%%%%%%%%%%

% Set initial audio parameters:
nrchannels = 1; % All stimuli are mono-sounds.
freq = 44100;

% Initialize sound driver.
InitializePsychSound;

try
    pahandle = PsychPortAudio('Open', [], [], 3, freq, nrchannels);
catch
    % If the above fails, use the audio device's standard frequency.
    psychlasterror('reset'); % I believe this some reseting of the error made in 'try'.
    pahandle = PsychPortAudio('Open', [], [], 3, [], nrchannels);
end



%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%
%%%%% MAIN LOOP %%%%%
%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%


home = '/Users/josh/Dropbox/Beverlab/Fall_2013_Study/Design/Matlab/'

SampleExperiment = {strcat(home,'Stimuli/tokensA/gipa_mono.wav'),...
    strcat(home,'Stimuli/tokensB/gabo_mono.wav')};


timeLimit = 10; % Set up the time limit.
ans = 0;  % This is used to track whether or not the participant answered.
numStim = 2; % Just using 2 right now to test the code

ListenChar(0);

for i=1:numStim;
    token = char(SampleExperiment(1,randi([1,2]))); % randomly select a wave file from 'SampleExperiment' and assign it to 'token'
    [y,freq] = wavread(token); % Read the current wav file.
    wavedata = y';  % Transpose wav data.
    PsychPortAudio('FillBuffer', pahandle, wavedata); % fill the buffer, ready to play
    t1 = PsychPortAudio('Start', pahandle, 1, 0, 1); % play the wave file and get timestamp in one go

    while GetSecs<t1+timeLimit
        if ans<6
            [secs, keyCode, deltaSecs] = KbWait([],2,t1+timeLimit);
            if isempty(find(keyCode,1))
                break
            end
            if ~isempty(find(keyCode,1))
                ans=ans+1;
            end
        end
        if ans==6
            WaitSecs(rand*3+1);
            break
        end
    end
    if ans<6
        DrawFormattedText(window, 'Lets try that again...press 6 times', 'center', 'center');
        Screen(window, 'Flip');
        WaitSecs(1);
        Screen(window, 'FillRect', white);
        Screen(window, 'Flip');

        [y,freq] = wavread(token); % Read the current wav file.
        wavedata = y';  % Transpose wav data.
        PsychPortAudio('FillBuffer', pahandle, wavedata); % fill the buffer, ready to play
        t1 = PsychPortAudio('Start', pahandle, 1, 0, 1); % play the wave file and get timestamp in one go

        while GetSecs<t1+timeLimit
            if ans<6
                [secs, keyCode, deltaSecs] = KbWait([],2,t1+timeLimit);
                if isempty(find(keyCode,1))
                    break
                end
                if ~isempty(find(keyCode,1))
                    ans=ans+1;
                end
            end
            if ans==6
                WaitSecs(rand*3+1);
                break
            end
        end
    end
end


Screen('CloseAll')   

Upvotes: 2

Views: 2727

Answers (2)

This crashing is likely due to a new bug in OSX 10.8.4, causing PsychToolBox to crash on closing the connection to the display server (and apparently bringing MATLAB with it). See here for discussion and resolution.

Anybody still having this issue, please update to the latest version of PsychToolBox (which is always a good idea!)

Upvotes: 1

Edric
Edric

Reputation: 25140

This sort of error usually indicates something drastic and unrecoverable has happened. It appears that the Psychtoolbox contains MEX files, that is probably the most likely culprit. I would either attempt to rebuild those using R2013b, or contact the authors to see if they have a version compatible with R2013b.

Upvotes: 1

Related Questions