Skip to content
This repository was archived by the owner on Feb 27, 2023. It is now read-only.

Commit 88795bf

Browse files
menduzkuruk-mm
andauthored
feat: fail if major performance caveat (#587)
* do not fail silently * normalize error reporting * Update packages/unity-interface/initializer.ts * Update packages/unity-interface/initializer.ts Co-authored-by: Mateo Miccino <mateomiccino@gmail.com>
1 parent 8485118 commit 88795bf

11 files changed

Lines changed: 69 additions & 37 deletions

File tree

packages/entryPoints/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare const globalThis: { DecentralandKernel: IDecentralandKernel }
33
import { sdk } from '@dcl/schemas'
44
import { createLogger } from 'shared/logger'
55
import { IDecentralandKernel, IEthereumProvider, KernelOptions, KernelResult, LoginState } from '@dcl/kernel-interface'
6-
import { BringDownClientAndShowError, ErrorContext, ReportFatalError } from 'shared/loading/ReportFatalError'
6+
import { ErrorContext, BringDownClientAndReportFatalError } from 'shared/loading/ReportFatalError'
77
import { renderingInBackground, renderingInForeground } from 'shared/loading/types'
88
import { gridToWorld, worldToGrid } from '../atomicHelpers/parcelScenePositions'
99
import {
@@ -120,8 +120,7 @@ globalThis.DecentralandKernel = {
120120
setTimeout(
121121
() =>
122122
initInternal().catch((err) => {
123-
ReportFatalError(err, ErrorContext.WEBSITE_INIT)
124-
BringDownClientAndShowError(err.toString())
123+
BringDownClientAndReportFatalError(err, ErrorContext.WEBSITE_INIT)
125124
}),
126125
0
127126
)
@@ -223,7 +222,7 @@ async function loadWebsiteSystems(options: KernelOptions['kernelOptions']) {
223222
const profile = getCurrentUserProfile(store.getState())!
224223

225224
if (!profile) {
226-
ReportFatalError(new Error('Profile missing during unity initialization'), 'kernel#init')
225+
BringDownClientAndReportFatalError(new Error('Profile missing during unity initialization'), 'kernel#init')
227226
return
228227
}
229228

packages/shared/analytics/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,6 @@ export type TrackEvents = PositionTrackEvents & {
7878
['Control Friend deleted']: Record<string, never> // {}
7979
// TODO - the above metrics are reintroduced for control, remove asap - moliva - 2022/06/01
8080
['Remote avatar for profile is invalid']: { avatar: Avatar }
81+
82+
['pickedRealm']: { algorithm: string; domain: string }
8183
}

packages/shared/dao/pick-realm-algorithm/closePeers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function closePeersScoreLink({
2222
name: AlgorithmLinkTypes.CLOSE_PEERS_SCORE,
2323
pick: (context: AlgorithmContext) => {
2424
const score = defaultScoreAddons(latencyDeductionsParameters, baseScore, closeUsersScore(context.userParcel))
25-
return selectFirstByScore(context, score, definitiveDecisionThreshold, true) // If we have less than 10 users of difference by default, we cannot make a definitive decision. It delegates to the next link
25+
return selectFirstByScore(context, score, definitiveDecisionThreshold, true)
2626
}
2727
}
2828
}

packages/shared/dao/pick-realm-algorithm/defaults.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export const defaultAllPeersScoreConfig: AllPeersScoreParameters = {
2626
baseScore: 40,
2727
fillTargetPercentage: 0.5,
2828
discourageFillTargetPercentage: 0.8,
29-
definitiveDecisionThreshold: 20,
29+
// If we have less than 20 users of difference by default, we cannot make a definitive decision. It delegates to the next link
30+
definitiveDecisionThreshold: 10,
3031
latencyDeductionsParameters: {
3132
exponentialDivisor: 900,
3233
multiplier: 60,

packages/shared/dao/pick-realm-algorithm/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { largeLatencyLink } from './largeLatency'
66
import { closePeersScoreLink } from './closePeers'
77
import { allPeersScoreLink } from './allPeers'
88
import { loadBalancingLink } from './loadBalancing'
9+
import { trackEvent } from 'shared/analytics'
910

1011
function buildLink(linkConfig: AlgorithmLinkConfig) {
1112
switch (linkConfig.type) {
@@ -65,6 +66,12 @@ export function createAlgorithm(config: AlgorithmChainConfig) {
6566
// If a link picks a particular candidate, we return that
6667
if (context.selected) {
6768
defaultLogger.log(`Picked candidate using algorithm link: ${link.name}`, context.selected)
69+
70+
trackEvent('pickedRealm', {
71+
algorithm: link.name,
72+
domain: context.selected.domain
73+
})
74+
6875
return context.selected
6976
}
7077

packages/shared/dao/sagas.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ import {
2424
getUpdateProfileServer
2525
} from './selectors'
2626
import { saveToPersistentStorage, getFromPersistentStorage } from '../../atomicHelpers/persistentStorage'
27-
import {
28-
BringDownClientAndShowError,
29-
ErrorContext,
30-
ReportFatalErrorWithCatalystPayload
31-
} from 'shared/loading/ReportFatalError'
32-
import { CATALYST_COULD_NOT_LOAD } from 'shared/loading/types'
27+
import { BringDownClientAndReportFatalError } from 'shared/loading/ReportFatalError'
3328
import { gte } from 'semver'
3429
import { commsLogger } from 'shared/comms/context'
3530
import { parseParcelPosition } from 'atomicHelpers/parcelScenePositions'
@@ -120,8 +115,7 @@ export function* selectAndReconnectRealm() {
120115
// if no realm was selected, then do the whole initialization dance
121116
} catch (e: any) {
122117
debugger
123-
ReportFatalErrorWithCatalystPayload(e, ErrorContext.KERNEL_INIT)
124-
BringDownClientAndShowError(CATALYST_COULD_NOT_LOAD)
118+
BringDownClientAndReportFatalError(e, 'comms#init')
125119
throw e
126120
}
127121
}

packages/shared/loading/ReportFatalError.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { globalObservable } from '../observables'
1111
import { getUnityInstance } from 'unity-interface/IUnityInterface'
1212
import { store } from 'shared/store/isolatedStore'
1313

14-
export function BringDownClientAndShowError(event: ExecutionLifecycleEvent) {
15-
if (ExecutionLifecycleEventsList.includes(event)) {
14+
export function BringDownClientAndShowError(event: ExecutionLifecycleEvent | string) {
15+
if (ExecutionLifecycleEventsList.includes(event as any)) {
1616
store.dispatch(action(event))
1717
}
1818

@@ -51,12 +51,12 @@ export type ErrorContextTypes =
5151

5252
export function ReportFatalErrorWithCatalystPayload(error: Error, context: ErrorContextTypes) {
5353
// TODO(Brian): Get some useful catalyst payload to append here
54-
ReportFatalError(error, context)
54+
BringDownClientAndReportFatalError(error, context)
5555
}
5656

5757
export function ReportFatalErrorWithCommsPayload(error: Error, context: ErrorContextTypes) {
5858
// TODO(Brian): Get some useful comms payload to append here
59-
ReportFatalError(error, context)
59+
BringDownClientAndReportFatalError(error, context)
6060
}
6161

6262
export function ReportFatalErrorWithUnityPayload(error: Error, context: ErrorContextTypes) {
@@ -69,18 +69,27 @@ export function ReportFatalErrorWithUnityPayload(error: Error, context: ErrorCon
6969
})
7070
}
7171

72-
Object.assign(globalThis, { BringDownClientAndShowError, ReportFatalErrorWithUnityPayloadAsync, ReportFatalError })
72+
Object.assign(globalThis, {
73+
BringDownClientAndShowError,
74+
ReportFatalErrorWithUnityPayloadAsync,
75+
ReportFatalError: BringDownClientAndReportFatalError,
76+
BringDownClientAndReportFatalError
77+
})
7378

7479
export async function ReportFatalErrorWithUnityPayloadAsync(error: Error, context: ErrorContextTypes) {
7580
try {
7681
const payload = await getUnityInstance().CrashPayloadRequest()
77-
ReportFatalError(error, context, { rendererPayload: payload })
82+
BringDownClientAndReportFatalError(error, context, { rendererPayload: payload })
7883
} catch (e) {
79-
ReportFatalError(error, context)
84+
BringDownClientAndReportFatalError(error, context)
8085
}
8186
}
8287

83-
export function ReportFatalError(error: Error, context: ErrorContextTypes, payload: Record<string, any> = {}) {
88+
export function BringDownClientAndReportFatalError(
89+
error: Error,
90+
context: ErrorContextTypes,
91+
payload: Record<string, any> = {}
92+
) {
8493
let sagaStack: string | undefined = payload['sagaStack']
8594

8695
debugger

packages/shared/profiles/sagas.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import { fetchOwnedENS } from 'shared/web3'
3838
import { waitForRealmInitialized } from 'shared/dao/sagas'
3939
import { base64ToBuffer } from 'atomicHelpers/base64ToBlob'
4040
import { LocalProfilesRepository } from './LocalProfilesRepository'
41-
import { BringDownClientAndShowError, ErrorContext, ReportFatalError } from 'shared/loading/ReportFatalError'
42-
import { UNEXPECTED_ERROR } from 'shared/loading/types'
41+
import { ErrorContext, BringDownClientAndReportFatalError } from 'shared/loading/ReportFatalError'
4342
import { store } from 'shared/store/isolatedStore'
4443
import { createFakeName } from './utils/fakeName'
4544
import { getCommsContext } from 'shared/comms/selectors'
@@ -100,8 +99,7 @@ function* initialRemoteProfileLoad() {
10099
try {
101100
profile = yield call(ProfileAsPromise, userId, undefined, isGuest ? ProfileType.LOCAL : ProfileType.DEPLOYED)
102101
} catch (e: any) {
103-
ReportFatalError(e, ErrorContext.KERNEL_INIT, { userId })
104-
BringDownClientAndShowError(UNEXPECTED_ERROR)
102+
BringDownClientAndReportFatalError(e, ErrorContext.KERNEL_INIT, { userId })
105103
throw e
106104
}
107105

packages/shared/store/store.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createLogger } from 'redux-logger'
44
import { reducers } from './rootReducer'
55
import { createRootSaga } from './rootSaga'
66
import { DEBUG_REDUX } from '../../config'
7-
import { BringDownClientAndShowError, ErrorContext, ReportFatalError } from '../loading/ReportFatalError'
7+
import { ErrorContext, BringDownClientAndReportFatalError } from '../loading/ReportFatalError'
88
import defaultLogger from '../logger'
99
import { setStore } from './isolatedStore'
1010
import { composeWithDevTools } from 'redux-devtools-extension'
@@ -17,8 +17,7 @@ export const buildStore = () => {
1717
sagaMonitor,
1818
onError: (error: Error, { sagaStack }: { sagaStack: string }) => {
1919
defaultLogger.log('SAGA-ERROR: ', error)
20-
ReportFatalError(error, ErrorContext.KERNEL_SAGA, { sagaStack })
21-
BringDownClientAndShowError(error.message as any)
20+
BringDownClientAndReportFatalError(error, ErrorContext.KERNEL_SAGA, { sagaStack })
2221
}
2322
})
2423

packages/unity-interface/initializer.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ async function loadInjectedUnityDelegate(container: HTMLElement): Promise<UnityG
5656

5757
const { originalUnity, engineStartedFuture } = await createWebRenderer(canvas)
5858

59+
const ctx: WebGL2RenderingContext = (originalUnity.Module as any).ctx
60+
61+
const debug_ext = ctx.getExtension('WEBGL_debug_renderer_info')
62+
if (debug_ext) {
63+
const renderer = ctx.getParameter(debug_ext.UNMASKED_RENDERER_WEBGL)
64+
if (renderer.indexOf('SwiftShader') >= 0) {
65+
throw new Error(
66+
'Your browser is using an emulated software renderer (SwiftShader). This prevents Decentraland from working. This is usually fixed by restarting the computer. In any case, we recommend you to use the Desktop Client instead for a better overall experience. You can find it in https://decentraland.org/download'
67+
)
68+
}
69+
}
70+
71+
canvas.addEventListener(
72+
'webglcontextlost',
73+
function (event) {
74+
event.preventDefault()
75+
BringDownClientAndShowError(
76+
'The rendering engine failed. This is an unrecoverable error that is subject to the available memory and resources of your browser.\n' +
77+
'For a better experience, we recommend using the Native Desktop Client. You can find it in https://decentraland.org/download'
78+
)
79+
},
80+
false
81+
)
82+
5983
// TODO: move to unity-renderer js project
6084
originalUnity.Module.errorHandler = (message: string, filename: string, lineno: number) => {
6185
console['error'](message, filename, lineno)

0 commit comments

Comments
 (0)