Skip to content

Commit

Permalink
Prevent possible crashes of the editor in multiple part of the app (#…
Browse files Browse the repository at this point in the history
…5883)

Do not show in changelog
  • Loading branch information
ClementPasteau authored Nov 9, 2023
1 parent 2965f37 commit d39cfd1
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 18 deletions.
2 changes: 1 addition & 1 deletion newIDE/app/src/AssetStore/AssetStoreContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export const AssetStoreStateProvider = ({

const publicAssetPacksByTag = React.useMemo(
() => {
if (!publicAssetPacks) {
if (!publicAssetPacks || !publicAssetPacks.starterPacks) {
return null;
}
const publicAssetPacksByTag = {};
Expand Down
4 changes: 4 additions & 0 deletions newIDE/app/src/InAppTutorial/InAppTutorialOrchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ const translateAndInterpolateText = ({
} else {
translatedText = i18n._(text.messageDescriptor, data);
}

// Something went wrong with the translation, let's hide the text.
if (typeof translatedText !== 'string') return '';

return interpolateText(translatedText, data, project);
};

Expand Down
20 changes: 15 additions & 5 deletions newIDE/app/src/InstancesEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,21 @@ export default class InstancesEditor extends Component<Props> {
// to protect against renders after the component is unmounted.
this._unmounted = true;

this.selectionRectangle.delete();
this.instancesRenderer.delete();
this._instancesAdder.unmount();
this.pinchHandler.unmount();
this.longTouchHandler.unmount();
if (this.selectionRectangle) {
this.selectionRectangle.delete();
}
if (this.instancesRenderer) {
this.instancesRenderer.delete();
}
if (this._instancesAdder) {
this._instancesAdder.unmount();
}
if (this.pinchHandler) {
this.pinchHandler.unmount();
}
if (this.longTouchHandler) {
this.longTouchHandler.unmount();
}
if (this.nextFrame) cancelAnimationFrame(this.nextFrame);
stopPIXITicker();
this.pixiContainer.destroy();
Expand Down
3 changes: 3 additions & 0 deletions newIDE/app/src/SceneEditor/MosaicEditorsDisplay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ const MosaicEditorsDisplay = React.forwardRef<
const selectedObjectNames = props.selectedObjectFolderOrObjectsWithContext
.map(objectFolderOrObjectWithContext => {
const { objectFolderOrObject } = objectFolderOrObjectWithContext;

if (!objectFolderOrObject) return null; // Protect ourselves from an unexpected null value.

if (objectFolderOrObject.isFolder()) return null;
return objectFolderOrObject.getObject().getName();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ const SwipeableDrawerEditorsDisplay = React.forwardRef<
const selectedObjectNames = props.selectedObjectFolderOrObjectsWithContext
.map(objectFolderOrObjectWithContext => {
const { objectFolderOrObject } = objectFolderOrObjectWithContext;

if (!objectFolderOrObject) return null; // Protect ourselves from an unexpected null value.

if (objectFolderOrObject.isFolder()) return null;
return objectFolderOrObject.getObject().getName();
})
Expand Down
16 changes: 13 additions & 3 deletions newIDE/app/src/Utils/GDevelopServices/Asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,20 @@ export const listAllPublicAssets = async ({
throw new Error('Unexpected response from the assets endpoints.');
}

const publicAssetShortHeaders = responsesData[0];
const publicFilters = responsesData[1];
const publicAssetPacks = responsesData[2];

if (!publicAssetPacks.starterPacks) {
throw new Error(
'Unexpected response from the public asset packs endpoint.'
);
}

return {
publicAssetShortHeaders: responsesData[0],
publicFilters: responsesData[1],
publicAssetPacks: responsesData[2],
publicAssetShortHeaders,
publicFilters,
publicAssetPacks,
};
};

Expand Down
20 changes: 12 additions & 8 deletions newIDE/app/src/Utils/GDevelopServices/Release.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ export type Release = {
description: ?string,
};

export const getReleases = (): Promise<Array<Release>> => {
return axios
.get(`${GDevelopReleaseApi.baseUrl}/release`, {
params: {
last: 4,
},
})
.then(response => response.data);
export const getReleases = async (): Promise<Array<Release>> => {
const response = await axios.get(`${GDevelopReleaseApi.baseUrl}/release`, {
params: {
last: 4,
},
});
const releases = response.data;
if (!Array.isArray(releases)) {
throw new Error('Invalid releases');
}

return releases;
};

export const hasBreakingChange = (release: Release): boolean => {
Expand Down
7 changes: 6 additions & 1 deletion newIDE/app/src/Utils/GDevelopServices/Shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ export const listListedPrivateGameTemplates = async ({
withAppStoreProductId: !!onlyAppStorePrivateGameTemplates,
},
});
return response.data;
const gameTemplates = response.data;
if (!Array.isArray(gameTemplates)) {
throw new Error('Invalid game templates');
}

return gameTemplates;
};

export const listSellerAssetPacks = async ({
Expand Down

0 comments on commit d39cfd1

Please sign in to comment.