Bug fix: prevent KCL error due to colliding AST execution on project switch (#3205)
* Only run "Execute AST" action if defaultUnit setting changes * A little more logging and catching anywhere we call video.play()
This commit is contained in:
@ -142,7 +142,9 @@ export const ModelingMachineProvider = ({
|
|||||||
kclManager.executeCode().then(() => {
|
kclManager.executeCode().then(() => {
|
||||||
if (engineCommandManager.engineConnection?.idleMode) return
|
if (engineCommandManager.engineConnection?.idleMode) return
|
||||||
|
|
||||||
store.videoElement?.play()
|
store.videoElement?.play().catch((e) => {
|
||||||
|
console.warn('Video playing was prevented', e)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})()
|
})()
|
||||||
},
|
},
|
||||||
|
@ -175,11 +175,35 @@ export const SettingsAuthProviderBase = ({
|
|||||||
id: `${event.type}.success`,
|
id: `${event.type}.success`,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
'Execute AST': () => {
|
'Execute AST': (context, event) => {
|
||||||
kclManager.isFirstRender = true
|
try {
|
||||||
kclManager.executeCode(true).then(() => {
|
const allSettingsIncludesUnitChange =
|
||||||
kclManager.isFirstRender = false
|
event.type === 'Set all settings' &&
|
||||||
})
|
event.settings?.modeling?.defaultUnit?.current !==
|
||||||
|
context.modeling.defaultUnit.current
|
||||||
|
const resetSettingsIncludesUnitChange =
|
||||||
|
event.type === 'Reset settings' &&
|
||||||
|
context.modeling.defaultUnit.current !==
|
||||||
|
settings?.modeling?.defaultUnit?.default
|
||||||
|
|
||||||
|
if (
|
||||||
|
event.type === 'set.modeling.defaultUnit' ||
|
||||||
|
allSettingsIncludesUnitChange ||
|
||||||
|
resetSettingsIncludesUnitChange
|
||||||
|
) {
|
||||||
|
kclManager.isFirstRender = true
|
||||||
|
kclManager.executeCode(true).then(() => {
|
||||||
|
kclManager.isFirstRender = false
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
// For any future logging we'd like to do
|
||||||
|
// console.log(
|
||||||
|
// 'Not re-executing AST because the settings change did not affect the code interpretation'
|
||||||
|
// )
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error executing AST after settings change', e)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
services: {
|
services: {
|
||||||
|
@ -156,7 +156,10 @@ export const Stream = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setIsFirstRender(kclManager.isFirstRender)
|
setIsFirstRender(kclManager.isFirstRender)
|
||||||
if (!kclManager.isFirstRender) videoRef.current?.play()
|
if (!kclManager.isFirstRender)
|
||||||
|
videoRef.current?.play().catch((e) => {
|
||||||
|
console.warn('Video playing was prevented', e)
|
||||||
|
})
|
||||||
setIsFreezeFrame(!kclManager.isFirstRender)
|
setIsFreezeFrame(!kclManager.isFirstRender)
|
||||||
}, [kclManager.isFirstRender])
|
}, [kclManager.isFirstRender])
|
||||||
|
|
||||||
@ -170,8 +173,12 @@ export const Stream = () => {
|
|||||||
if (!mediaStream) return
|
if (!mediaStream) return
|
||||||
|
|
||||||
// Do not immediately play the stream!
|
// Do not immediately play the stream!
|
||||||
videoRef.current.srcObject = mediaStream
|
try {
|
||||||
videoRef.current.pause()
|
videoRef.current.srcObject = mediaStream
|
||||||
|
videoRef.current.pause()
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('Attempted to pause stream while play was still loading', e)
|
||||||
|
}
|
||||||
|
|
||||||
send({
|
send({
|
||||||
type: 'Set context',
|
type: 'Set context',
|
||||||
|
@ -224,6 +224,7 @@ export class KclManager {
|
|||||||
|
|
||||||
sceneInfra.modelingSend({ type: 'code edit during sketch' })
|
sceneInfra.modelingSend({ type: 'code edit during sketch' })
|
||||||
defaultSelectionFilter(programMemory, this.engineCommandManager)
|
defaultSelectionFilter(programMemory, this.engineCommandManager)
|
||||||
|
await this.engineCommandManager.waitForAllCommands()
|
||||||
|
|
||||||
if (zoomToFit) {
|
if (zoomToFit) {
|
||||||
let zoomObjectId: string | undefined = ''
|
let zoomObjectId: string | undefined = ''
|
||||||
@ -243,6 +244,15 @@ export class KclManager {
|
|||||||
padding: 0.1, // padding around the objects
|
padding: 0.1, // padding around the objects
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
await this.engineCommandManager.sendSceneCommand({
|
||||||
|
type: 'modeling_cmd_req',
|
||||||
|
cmd_id: uuidv4(),
|
||||||
|
cmd: {
|
||||||
|
type: 'zoom_to_fit',
|
||||||
|
object_ids: zoomObjectId ? [zoomObjectId] : [], // leave empty to zoom to all objects
|
||||||
|
padding: 0.1, // padding around the objects
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isExecuting = false
|
this.isExecuting = false
|
||||||
|
@ -1082,7 +1082,9 @@ export const modelingMachine = createMachine(
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if (!engineCommandManager.engineConnection?.idleMode) {
|
if (!engineCommandManager.engineConnection?.idleMode) {
|
||||||
store.videoElement?.play()
|
store.videoElement?.play().catch((e) => {
|
||||||
|
console.warn('Video playing was prevented', e)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (updatedAst?.selections) {
|
if (updatedAst?.selections) {
|
||||||
editorManager.selectRange(updatedAst?.selections)
|
editorManager.selectRange(updatedAst?.selections)
|
||||||
|
Reference in New Issue
Block a user