Skip to content
Snippets Groups Projects
Commit 75fbc8d2 authored by Paul Kaplan's avatar Paul Kaplan
Browse files

Fix trying to load sound index out of range.

parent 4e736d39
No related branches found
No related tags found
No related merge requests found
......@@ -190,8 +190,11 @@ SoundEditor.propTypes = {
};
const mapStateToProps = (state, {soundIndex}) => {
const sound = state.vm.editingTarget.sprite.sounds[soundIndex];
const audioBuffer = state.vm.getSoundBuffer(soundIndex);
const sprite = state.vm.editingTarget.sprite;
// Make sure the sound index doesn't go out of range.
const index = soundIndex < sprite.sounds.length ? soundIndex : sprite.sounds.length - 1;
const sound = state.vm.editingTarget.sprite.sounds[index];
const audioBuffer = state.vm.getSoundBuffer(index);
return {
soundId: sound.soundId,
sampleRate: audioBuffer.sampleRate,
......
......@@ -272,4 +272,28 @@ describe('costumes, sounds and variables', () => {
const logs = await getLogs(errorWhitelist);
await expect(logs).toEqual([]);
});
// Regression test for gui issue #1320
test('Switching sprites with different numbers of sounds', async () => {
await loadUri(uri);
await clickXpath('//button[@title="tryit"]');
// Add a sound so this sprite has 2 sounds.
await clickText('Sounds');
await clickText('Add Sound');
await clickText('A Bass'); // Closes the modal
// Now add a sprite with only one sound.
await clickText('Add Sprite');
await clickText('Abby'); // Doing this used to crash the editor.
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for error
// Make sure the 'Oops' screen is not visible
const content = await driver.getPageSource();
expect(content.indexOf('Oops')).toEqual(-1);
const logs = await getLogs(errorWhitelist);
await expect(logs).toEqual([]);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment