@@ -1590,7 +1590,8 @@ static struct ra_tex **next_hook_tex(struct gl_video *p)
15901590// Process hooks for a plane, saving the result and returning a new image
15911591// If 'trans' is NULL, the shader is forbidden from transforming img
15921592static struct image pass_hook (struct gl_video * p , const char * name ,
1593- struct image img , struct gl_transform * trans )
1593+ struct image img , struct gl_transform * trans ,
1594+ int max_output_components )
15941595{
15951596 if (!name )
15961597 return img ;
@@ -1618,6 +1619,14 @@ static struct image pass_hook(struct gl_video *p, const char *name,
16181619
16191620 const char * store_name = hook -> save_tex ? hook -> save_tex : name ;
16201621 bool is_overwrite = strcmp (store_name , name ) == 0 ;
1622+ int comps = hook -> components ? hook -> components : img .components ;
1623+
1624+ if (is_overwrite && comps > max_output_components ) {
1625+ MP_ERR (p , "Hook tried to overwrite %s COMPONENTS to "
1626+ "unsupported value: %d (max supported: %d)\n" ,
1627+ name , comps , max_output_components );
1628+ continue ;
1629+ }
16211630
16221631 // If user shader is set to align HOOKED with reference and fix its
16231632 // offset, it requires HOOKED to be resizable and overwritten.
@@ -1643,7 +1652,6 @@ static struct image pass_hook(struct gl_video *p, const char *name,
16431652 struct gl_transform hook_off = identity_trans ;
16441653 hook -> hook (p , img , & hook_off , hook -> priv );
16451654
1646- int comps = hook -> components ? hook -> components : img .components ;
16471655 skip_unused (p , comps );
16481656
16491657 // Compute the updated FBO dimensions and store the result
@@ -1718,7 +1726,7 @@ found: ;
17181726 struct ra_tex * * tex = next_hook_tex (p );
17191727 finish_pass_tex (p , tex , p -> texture_w , p -> texture_h );
17201728 struct image img = image_wrap (* tex , PLANE_RGB , p -> components );
1721- img = pass_hook (p , name , img , tex_trans );
1729+ img = pass_hook (p , name , img , tex_trans , 4 );
17221730 copy_image (p , & (int ){0 }, img );
17231731 p -> texture_w = img .w ;
17241732 p -> texture_h = img .h ;
@@ -2297,7 +2305,7 @@ static void pass_read_video(struct gl_video *p)
22972305 default : continue ;
22982306 }
22992307
2300- img [n ] = pass_hook (p , name , img [n ], & offsets [n ]);
2308+ img [n ] = pass_hook (p , name , img [n ], & offsets [n ], img [ n ]. components );
23012309
23022310 if (reference_tex_num == n ) {
23032311 // The reference texture is finalized now.
@@ -2417,7 +2425,7 @@ static void pass_read_video(struct gl_video *p)
24172425 }
24182426
24192427 // Run any post-scaling hooks
2420- img [n ] = pass_hook (p , name , img [n ], NULL );
2428+ img [n ] = pass_hook (p , name , img [n ], NULL , img [ n ]. components );
24212429 }
24222430
24232431 // All planes are of the same size and properly aligned at this point
0 commit comments