Fix WebGPU renderer initialization order

This commit is contained in:
sudhir
2026-04-15 10:49:51 +05:30
parent f25806ee8f
commit 3ac26bf635
2 changed files with 3 additions and 34 deletions
@@ -106,11 +106,11 @@ const Viewer: React.FC<ViewerProps> = ({
camera={{ position: [50, 50, 50], fov: 50 }} camera={{ position: [50, 50, 50], fov: 50 }}
className={`transition-colors duration-700 ${theme === 'dark' ? 'bg-[#1f2433]' : 'bg-[#fafafa]'}`} className={`transition-colors duration-700 ${theme === 'dark' ? 'bg-[#1f2433]' : 'bg-[#fafafa]'}`}
dpr={[1, 1.5]} dpr={[1, 1.5]}
gl={(props) => { gl={async (props) => {
const renderer = new THREE.WebGPURenderer(props as any) const renderer = new THREE.WebGPURenderer(props as any)
renderer.toneMapping = THREE.ACESFilmicToneMapping renderer.toneMapping = THREE.ACESFilmicToneMapping
renderer.toneMappingExposure = 0.9 renderer.toneMappingExposure = 0.9
// renderer.init() // Only use when using <DebugRenderer /> await renderer.init()
return renderer return renderer
}} }}
resize={{ resize={{
@@ -53,7 +53,6 @@ const PostProcessingPasses = () => {
const hasPipelineErrorRef = useRef(false) const hasPipelineErrorRef = useRef(false)
const retryCountRef = useRef(0) const retryCountRef = useRef(0)
const rebuildTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null) const rebuildTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const [isInitialized, setIsInitialized] = useState(false)
// Background color uniform — updated every frame via lerp, read by the TSL pipeline. // Background color uniform — updated every frame via lerp, read by the TSL pipeline.
// Initialised from the current theme so there's no flash on first render. // Initialised from the current theme so there's no flash on first render.
@@ -85,35 +84,6 @@ const PostProcessingPasses = () => {
setPipelineVersion((v) => v + 1) setPipelineVersion((v) => v + 1)
}, []) }, [])
// Renderer initialization
useEffect(() => {
let mounted = true
const initRenderer = async () => {
try {
if (renderer && (renderer as any).init) {
await (renderer as any).init()
}
if (mounted) {
setIsInitialized(true)
}
} catch (error) {
console.error('[viewer] Failed to initialize renderer for post-processing.', error)
if (mounted) {
setIsInitialized(false)
}
}
}
initRenderer()
return () => {
mounted = false
}
}, [renderer])
// Reset retry state when project changes // Reset retry state when project changes
useEffect(() => { useEffect(() => {
// Intentionally touch projectId so the effect reruns on project switches. // Intentionally touch projectId so the effect reruns on project switches.
@@ -141,7 +111,7 @@ const PostProcessingPasses = () => {
void projectId void projectId
void pipelineVersion void pipelineVersion
if (!(renderer && scene && camera && isInitialized)) { if (!(renderer && scene && camera)) {
return return
} }
@@ -298,7 +268,6 @@ const PostProcessingPasses = () => {
scene, scene,
camera, camera,
hoverHighlightMode, hoverHighlightMode,
isInitialized,
zoneLayers, zoneLayers,
projectId, projectId,
pipelineVersion, pipelineVersion,