@@ -18,11 +18,7 @@ class EffectPreviewService {
1818 this . loadPreviewImage ( ) ;
1919 }
2020
21- onPreviewImageReady ( {
22- callback,
23- } : {
24- callback : ( ) => void ;
25- } ) : ( ) => void {
21+ onPreviewImageReady ( { callback } : { callback : ( ) => void } ) : ( ) => void {
2622 this . onReadyCallbacks . add ( callback ) ;
2723 return ( ) => this . onReadyCallbacks . delete ( callback ) ;
2824 }
@@ -39,35 +35,47 @@ class EffectPreviewService {
3935 uniformDimensions ?: { width : number ; height : number } ;
4036 } ) : void {
4137 const size = PREVIEW_SIZE ;
42- const source = this . getTestSource ( { width : size , height : size } ) ;
43- if ( ! source ) return ;
44-
45- const definition = effectsRegistry . get ( effectType ) ;
46- const resolvedParams =
47- Object . keys ( params ) . length > 0
48- ? params
49- : buildDefaultParamValues ( definition . params ) ;
50-
51- const passes = resolveEffectPasses ( {
52- definition,
53- effectParams : resolvedParams ,
54- width : uniformDimensions ?. width ?? size ,
55- height : uniformDimensions ?. height ?? size ,
56- } ) ;
57- const result = this . applyGpuEffect ( {
58- source,
59- width : size ,
60- height : size ,
61- passes,
62- } ) ;
63-
6438 const targetCtx = targetCanvas . getContext (
6539 "2d" ,
6640 ) as CanvasRenderingContext2D | null ;
67- if ( targetCtx ) {
68- targetCanvas . width = size ;
69- targetCanvas . height = size ;
41+ if ( ! targetCtx ) {
42+ return ;
43+ }
44+
45+ targetCanvas . width = size ;
46+ targetCanvas . height = size ;
47+
48+ const source = this . getTestSource ( { width : size , height : size } ) ;
49+ if ( ! source ) {
50+ targetCtx . clearRect ( 0 , 0 , size , size ) ;
51+ return ;
52+ }
53+
54+ try {
55+ const definition = effectsRegistry . get ( effectType ) ;
56+ const resolvedParams =
57+ Object . keys ( params ) . length > 0
58+ ? params
59+ : buildDefaultParamValues ( definition . params ) ;
60+
61+ const passes = resolveEffectPasses ( {
62+ definition,
63+ effectParams : resolvedParams ,
64+ width : uniformDimensions ?. width ?? size ,
65+ height : uniformDimensions ?. height ?? size ,
66+ } ) ;
67+ const result = this . applyGpuEffect ( {
68+ source,
69+ width : size ,
70+ height : size ,
71+ passes,
72+ } ) ;
73+
7074 targetCtx . drawImage ( result , 0 , 0 , size , size ) ;
75+ } catch ( error ) {
76+ console . warn ( "Failed to render effect preview" , { effectType, error } ) ;
77+ targetCtx . clearRect ( 0 , 0 , size , size ) ;
78+ targetCtx . drawImage ( source , 0 , 0 , size , size ) ;
7179 }
7280 }
7381
0 commit comments