From 95177748ce9f6dafb880aea912842a4ff633eaac Mon Sep 17 00:00:00 2001 From: Adrian Wielgosik Date: Fri, 11 Oct 2024 21:16:05 +0200 Subject: [PATCH] avm2: Add exceptions for invalid surface selector --- core/src/avm2/globals.rs | 12 ++++++++ .../globals/flash/display3D/context_3d.rs | 28 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/core/src/avm2/globals.rs b/core/src/avm2/globals.rs index 884895ac59d9..dcc601f60b0c 100644 --- a/core/src/avm2/globals.rs +++ b/core/src/avm2/globals.rs @@ -201,6 +201,9 @@ pub struct SystemClassDefs<'gc> { pub graphicssolidfill: Class<'gc>, pub graphicsshaderfill: Class<'gc>, pub graphicsstroke: Class<'gc>, + + pub cubetexture: Class<'gc>, + pub rectangletexture: Class<'gc>, } impl<'gc> SystemClasses<'gc> { @@ -357,6 +360,9 @@ impl<'gc> SystemClassDefs<'gc> { graphicssolidfill: object, graphicsshaderfill: object, graphicsstroke: object, + + cubetexture: object, + rectangletexture: object, } } } @@ -959,6 +965,12 @@ pub fn init_native_system_classes(activation: &mut Activation<'_, '_>) { ), ("flash.display", "GraphicsSolidFill", graphicssolidfill), ("flash.display", "GraphicsStroke", graphicsstroke), + ("flash.display3D.textures", "CubeTexture", cubetexture), + ( + "flash.display3D.textures", + "RectangleTexture", + rectangletexture + ), ] ); } diff --git a/core/src/avm2/globals/flash/display3D/context_3d.rs b/core/src/avm2/globals/flash/display3D/context_3d.rs index 3c6f0a222148..016e8c99e2f2 100644 --- a/core/src/avm2/globals/flash/display3D/context_3d.rs +++ b/core/src/avm2/globals/flash/display3D/context_3d.rs @@ -599,6 +599,34 @@ pub fn set_render_to_texture<'gc>( let surface_selector = args.get_u32(activation, 3)?; let color_output_index = args.get_u32(activation, 4)?; + let mut error = None; + if texture.instance_class() == activation.avm2().class_defs().cubetexture { + if surface_selector > 5 { + error = Some(( + 3772, + "Error #3772: Cube textures need to have surfaceSelector [0..5].", + )); + } + } else if texture.instance_class() == activation.avm2().class_defs().rectangletexture { + if surface_selector != 0 { + error = Some(( + 3773, + "Error #3773: Rectangle textures need to have surfaceSelector = 0.", + )); + } + } else { + // normal Texture or video texture (but the latter should probably not be supported here anyway) + if surface_selector != 0 { + error = Some(( + 3771, + "Error #3771: 2D textures need to have surfaceSelector = 0.", + )); + } + } + if let Some((code, message)) = error { + return Err(Error::AvmError(argument_error(activation, message, code)?)); + } + if anti_alias != 0 { avm2_stub_method!( activation,