Skip to content

Commit

Permalink
avm2: Add exceptions for invalid surface selector
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian17 authored and Lord-McSweeney committed Oct 11, 2024
1 parent eaed811 commit 9517774
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/avm2/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -357,6 +360,9 @@ impl<'gc> SystemClassDefs<'gc> {
graphicssolidfill: object,
graphicsshaderfill: object,
graphicsstroke: object,

cubetexture: object,
rectangletexture: object,
}
}
}
Expand Down Expand Up @@ -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
),
]
);
}
Expand Down
28 changes: 28 additions & 0 deletions core/src/avm2/globals/flash/display3D/context_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9517774

Please sign in to comment.