We are not interested in testing the timing of buffer loads (since that will vary based on hardware), we just need to know that we got a buffer load event.
Furthermore all our seeks are in-buffer so multiple buffer full events shouldn't happen in Ruffle.
We previously ran these tags during preloading - however,
they are actually run as part of frame execution. This is observable
by ActionScript - a SWF can load in a class from a stop()'d MoveClip,
and then advance the clip to a frame with a SymbolClass referencing
the loaded class.
This fixes 'who_killed_travolta', and unblocks DeathvsMonstars and
NeoPets Lost City Lanes once some additional button fixes are merged.
This isn't 100% correct (as shown by the disabled test), but it brings
us closer to what Flash Player does.
* avm2: Add error 1087
* avm2: Add deep_copy method to XmlObject
Changes existing AS3 copy method to use this instead
* avm2: Add a few utility methods to E4XNode
* avm2: Change XML.replace impl to use new utility methods
* avm2: allow setting XML/XMLList as a element
* avm2: Fix `xml_namespaced_property` test failure
* chore: fmt
* chore: Appease clippy
* avm2: Add test for XML/XMLList as element
* avm2/tests: Implement XML.setName; add a test
* avm2: Basic support for QNames in XML.setName (no namespace support yet)
* avm2: Reorder order of Attribute/Element/PI checks in XML.setName
* avm2: Throw error #1117 when the name passed to XML.setName is not a valid XML name
SetTarget currently sets the target clip to the base clip if the
target passed to tellTarget() is an undefined object. This causes
goto's to run on the base clip in Ruffle, when Adobe Flash Player
does not run the goto's at all.
Fixes#12389 and #12390
`Loader` override `removeChild` and `removeChildAt` to try to prevent
user code from removing the loaded content child. However, this can be
bypassed by calling `otherContainer.addChild(loader.content)`, which
actually removes the child from the loader. Stealth Hunter 2 relies
on this behavior.
To make this work, `Loader.content` needs to go through
`contentLoaderInfo`, instead of relying on a child being present.
avm1_unload_movie has been adapted to only enter the unloaded state with
one frame delay if the MovieClip is a root MovieClip. The unloaded state
is now immediately entered for non-root MovieClips.
This fixes the regressions #12254 and #12265 which got introduced
because of this delay.
However, in Flash Player, even non-root MovieClips enter the unloaded
state one frame after the unloadMovie command has been read. Ruffle is
probably replacing a MovieClip differently to Flash, therefore
introducing these regressions when trying to emulate that delay.
Documentation explaining this all has been added to avm1_unload_movie.
Therefore, the test movieclip_library_state_values has been added. It
tests the default state and the unloaded state of a (non-root) child
MovieClip that's loaded from the library. It is marked as known_failure
because Ruffle currently doesn't implement the delay before entering the
unloaded state for non-root MovieClips.
Clears the read and write buffer of Socket before returning to ActionScript, this could potentially be problematic
when a SWF reuses the same Socket to connect.
Also remove the handle from Arena when server closes the connection, this fixes
connected still returning true after server disconnection.
Some of the tests are currently disabled because (separate from this PR)
we can't actually run `toString()` on a Vector.<Object>, due to our
broken vector handling.
* avm2+tests: Allow setting prototype to undefined
This is used internally by Adobe Flex in many places. Also add test.
* avm2: Set prototype when constructing a Function with null prototype
* tests: Expand prototype_set_null test
* chore: fmt
The special meta key `defaultValue` should be used to set
the default `value` field. Also, `index` is the position
within *just* the image or texture params, not within
all of the params.
Interfaces should only be listed when calling describeType
with a class instance (not with a `Class` object).
Additionally, AS3 methods can actually be displayed under
some circumstances. This is due to weird legacy behavior
that avmplus implements. A full fix requirs us to implement
namespace versioning, but we can get closer by special-casing
playerglobals (which is special-cased by namespace versioning
anyway).
The 'DisplayObject.visible' flag seems to be ignored for mask objects
(and their descendants) - mouse picking still takes them into account,
and they get rendered as part of the mask.
This commit changes display object rendering and AVM2 mouse picking
to ignore DisplayObject.visibility when dealing with mask objects/
descendants.
The suggested changes in the feedback to the pull request have been
implemented.
Therefore, this commit consists of multiple smaller changes:
- The unload_movie method has been renamed to avm1_unload_movie.
- The movieclip_default_state test now doesn't test
getTextSnapshot().getCount() because the underlying methods haven't
been implemented in AVM1 yet.
This should be reverted when they have been implemented or stubbed in
AVM1.
Two tests testing the different states of a MovieClip have been added.
A MovieClip can be in different specific states (namely: default state,
initial loading state, error state, image state, success state and
unloaded state). A state of a MovieClip consists of the values of all
properties and the results of some getter functions of the MovieClip.
To make sure that all of these states are implemented correctly and will
continue to be so in the future, two MovieClip state tests have been
added.
The movieclip_default_state test tests the default state of a MovieClip
after it has been created with createEmptyMovieClip.
The movieclip_state_values test has MovieClips going through all other
states and tests if the values are correct in each.
These tests currently only test the MovieClip states when trying to load
a local file since Ruffle tests currently don’t support tests using
remote URLs. Test cases for remote URLs are still included and can be
used if Ruffle starts supporting remote URLs at some point.
A HelperTest, which can be used to find out about how the state of a
MovieClip changes when trying to load and unload it, has been included
as well.
The behaviour of when the results of getBounds / getRect calls on
MovieClips with invalid bounds are 6710886.35 and when they are
6710886.4 for each corner of the rectangle is rather complex.
To make sure it works correctly in every case and will continue to do so
in the future, eight tests testing the results of getBounds calls under
these circumstances have been added.
This needs to be tested in several tests because an internal state
determining the results can change irreversibly. Making sure that it
changes correctly on different occasions takes several tests.
All NavigatorBackend implementations have been refactored, resulting in
improved code quality, less duplicated code, more consistent and easier
to understand procedures, additional error handling and better error
messages.
A resolve_url method has been added to the NavigatorBackend trait. It
takes a URL and and resolves it to the actual URL from which a file can
be fetched (including handling of relative links and pre-processing). It
has been implemented in each NavigatorBackend implementation.
Duplicated code has been put into new public functions in
core/src/backend/navigator.rs which are called by all NavigatorBackend
implementations.
ExternalNavigatorBackend:
- The navigate_to_url and fetch methods have been adapted to use
resolve_url, removing redundant code.
- Error handling has been added in case that the URL can't be converted
to a PathBuf.
- A TODO about differences between the flash player fetch and the
Ruffle fetch implementation has been added.
WebNavigatorBackend:
- The previous resolve_url method exclusively to the WebNavigatorBackend
has been replaced by the new resolve_url method. It is used by
navigate_to_url and fetch.
- resolve_url now always pre-processes the URL if it's valid (even if no
base_url exists) and explicitly returns whether the URL can be parsed.
- navigate_to_url now traces an explanatory error each if the URL can't
be parsed or is local.
- fetch now returns an explanatory error each if the URL can't be parsed
or is local (previously, a vague "Got JS error" has been returned).
TestNavigatorBackend & NullNavigatorBackend:
- fetch pre-processes the URL now (using the resolve_url implementation).
- If the URL isn't local, an explanatory error is returned (previously,
it was just an "Invalid URL" error).
- If the URL can't be parsed, an explanatory error with the reason is
returned (previously, it was just an "Invalid URL" error).
Additionally, error messages in all NavigatorBackend implementations
have been improved and made more consistent, e.g. if a local file can't
be read.
A load_error_swf function has been added to the Loader. It makes the
MovieClip enter the error state in which some attributes have certain
error values to signal that no valid file could be loaded. This happens
if no file could be loaded or if the loaded content is no valid
supported content.
The function creates an error state movie stub using the new
SwfMovie::error_movie function (which uses a new default_error_header
function) and configures remaining variables with the
movie_not_available method.
One TODO in order for the error state to be completely implemented has
been added.
Since the error state of the MovieClip includes the final URL of the SWF
file obtained after any redirects, the load_error_swf and
movie_loader_error functions (now) take an swf_url attribute.
To get this URL in case no file could be loaded, the
NavigatorBackend::fetch method has been changed to return an
ErrorResponse struct (including the url and the actual error) in the
error case. The Response struct returned in the success case has been
renamed to SuccessResponse.
All fetch implementations have been adapted accordingly. Code has been
adjusted to return the actual error where that's needed.
Documentation has been added and improved.
* avm2: Do not remove an EditText's selection on unfocus (fix#9006)
There are significant differences between how selection and caret info
work between AVM1 and AVM2.
In AVM1, there is only a single, global selection, which applies to
whichever element is currently focused. Therefore changing the focus
necessarily erases any information of what was selected before. There
can also be no active selection at all.
In AVM2, every text field has its own independent selection info. It is
NOT optional, the default selection is just a caret at position 0. If a
field loses focus, the selection is not rendered, but it is still
present. Movies such as #9006 rely on the same selection still being
there once you give back focus to the field.
Ruffle's model of selections (an Option per text field) is different
from both the AVM1 model (an optional singleton) and the AVM2 model
(mandatory per text field). This fix does not change that, it is only a
narrow fix targeted at 9006.
* avm2: implement selectionBegin/selectionEnd/caretIndex and add a test.
The selection test validates a few situations, including the behaviour
when unfocusing that was fixed in the previous commit.
The test does not validate how the selection changes after replacing
text, as there are still some inaccuracies there.
* avm2: Additional selection fixes needed after merging with master.
1. The default caret for an AVM2 textbox is at the end of the textbox,
not the beginning.
2. Selection should not be changed when focusing on a textbox in AVM2.
3. Fixed a test whose output.txt didn't actually match the flash player
output.
* avm2: Make the selection AVM checks compatible with mixed AVM, and revert the on_focus_changed parameters
---------
Co-authored-by: Nathan Adams <dinnerbone@dinnerbone.com>
Since this functionality was not enabled before, the reference image is
not deblocked. This commit disables deblocking for the test to match the
reference image, and eliminate deblocking as a source of differences.
When using a 'Loader', properties on the 'contentLoaderInfo' become
set during specific events in the load sequence. In particular,
'LoaderInfo.bytesTotal' becomes available during the first 'progress'
event.
Also, 'LoaderInfo.parameters' is now properly set from the URL query
parameters. In Flash player, this work even with filesystem urls
(e.g. 'file:///some/path/to/file.txt?paramOne=valOne' will load
a file named 'file.txt', setting and expose the parameter 'paramOne'
with value 'valOne' in `LoaderInfo.parameters`). This required some
cleanup to the desktop and test NavigatorBackend impls to strip
out query parameters when loading a parameter from disk.
Previously, we would set `SwfMovie.parameters` manually from the url.
Now, the various `SwfMovie` constructors automatically extract
query parameters from the provided url. Outside of `SwfMovie`,
we only append *extra* parameters (e.g. those set from `flashvars`).
This makes CPMStar ads work, since the loaded SWF needs to access
`LoaderInfo.parameters`
The 'winding' argument and filling behavior described in the docs
are not yet implemented. However, this implementation is good enough
for Scratch to render its default cat image.
We were previously only ever checking children,
and not attributes.
In order to avoid matching both attributes and elements
with a given name in 'descendants', `E4xNode::matches_name`
now checks `is_attribute` on the provided `Multiname`. This
requries changing several other parts of the codebase to
properly set this flag on `Multinames` provided by ActionScript.
You can also specify a `tick_rate` in order to get ticks faster or slower than the stage frame rate.
We also enable video decode and ticks on the netstream tests, since our netstream impl requires ticks.
`XML(someXMLObj)` and `XMLList(someXMLList)` perform the
normal cast behavior (returning the same object), instead
of creating a new object like other arguments do.
This also applies to `new XMLList(someXMLObj)`
and `XML(singleElemXMLList)`
* wpgu: Initial implementation of PixelBender shader execution
The implementation is split across four crates:
* `ruffle_render` now holds the main PixelBender bytecode parsing
implementation (previously, this was in `ruffle_core`).
* `ruffle_core` holds some helper functions for converting between
AVM2 `Value`s and the PixelBender vector types.
* `naga-pixelbender` (newly created) constructs a Naga `Module`
from parsed PixelBender bytecode
* `ruffle_render_wgpu` sets up the render pipeline for the shader
constructed by `naga-pixelbender`, and actually executes the shader.
The Actionscript-side shader parameters are passed in through uniforms.
This allows us to cache the compiled `naga::Module` and associated
wgpu types inside `ShaderData`, when it's first created. Each invocation
of a `ShaderJob` only needs to create a bind group and render pass.
Limitations:
* Only a few of the PixelBender opcodes are implemented - however, this is
enough to get Stemlands cannon rotation working, as well as a cool
"donut" shader that I found and included as a test.
* PixelBender matrix types are not supported.
* Only BitmapData is supported as an input/output type - Flash Player
also supports using Vector and ByteArray
* ShaderJob execution is always synchronous.
* Adjust comments
* Address review comments
We create a separate child domain, which is accessible
from the Stage and the root movieclip.
This prevents ActionScript from loading classes into the
special playerglobals domain (Domain.parentDomain is modified
to return null instead of the playerglobals domain when applicable),
so the native method lookup logic will never run for user code.
We now support deleting named children, as well as attributes.
Additionally, I've fixed our handling of `XML.parent()` - we now
properly set the parent when a child is created, and clear the parent
when `delete` is used.
If a child named 'foo' is removed by the timeline (without
having been previous added/removed from the timeline by ActionScript),
then the 'foo' field in the parent will be set to null. This occurs
even if the 'foo' field in the parent is not currently set to
the child 'foo' (e.g. 'this.foo = someOtherObject' was executed by
ActionScript).
The Adobe Animate compiler rejects a subclass that contains
a non-private field with the same name as a field in an ancestor
class (e.g. 'pub var foo:String' in both the subclass and superclass).
Unfortunately, Flash Player accepts this code, and creates a distinct
field for each class (even though they have the same namespace and
name). I suspect that this is caused by the optimizer replacing the
field accesses with internal slot accesses.
I've added an ignored test demonstrating this behavior - getting Ruffle
to reproduce it will be tricky.
When we run a 'goto', a weird "nested frame" gets triggered.
Previously, we were only calling `construct_frame` on the target
MovieClip as part of this "nested frame". However, Flash Player
seems to treat this (in some ways) like a normal frame - *all*
objects on the Stage (and orphans) have `construct_frame` called.
In particular, `gotoAndStop`/`gotoAndPlay` is called during
an "enterFrame" event handler, then unrelated objects on the Stage
will have their children constructed during the execution of
`gotoAndStop`/`gotoAndPlay`. The same logic holds for frame scripts.
This fixes a bug in Steamlands, which relies on children on the main
timeline being constructed immediately following a call to `gotoAndStop`
on an orphan (originally triggered from an "enterFrame" handler).
QName can contain characters like '.' and '<' as part of the
package or class name (though this requires editing the SWF
or using a nonstandard compiler). This broke our attempt to parse
generic type paramters by looking for '.<'
Instead, our 'Vector' special casing now operates on the unparsed
'AVMString' name, instead of attempting to construct a 'QName'.
This means that we don't need to handle generic paramters at
all for obfuscated names (which will never start with '__AS3__'
or 'Vector.<')
This fixes a bug in Red Ball 4v3, which has an obfuscated class
'!D.<H'
If we have two PlaceObject tags in the same frame with the same depth,
only the first one actually places an object. The second one is ignored
(Flash Player logs a warning).
We now parse PixelBender bytecode, and populate the parameters
from the bytecode on `ShaderData`. This is enough to progress
Steamlands, which needs to access dynamically set properties
on `ShaderData`
Bytecode execution is not implemented yet.
When we create a DisplayObject from ActionScript, we should always
run `construct_frame` on it, regardless of what frame phase we
are currently in.
This fixes a regression in Fancy Pants World 4 Part 1, where entering
the first door produced an error.
Flash Player performs `x + width` and `y + height` as floating
point operations before `round_to_even`. This affects the extent
covered by a `Rectangle` in various BitmapData methods, as the sum
of two values might be large enough to be rounded up to a larger
value (when rounding `x` and `width` individually would have
produced a smaller overall extent).
These are directly set on the underlying navigator's HTTP
request type, and get printed out in our test navigator backend.
No validation of the header names is performed - on web, this will be
enforced by the browser.
When we iterate over a render list (in order to call
`enter_frame`, `construct_frame, etc.) we need to be sure
that we iterate over all of the original `DisplayObjects`
in the list, even if the list is modified during iteration
(e.g. some ActionScript code calls `parent.addChildAt`).
Previously, `RenderIter` would repeatedly call `child_by_index`
on the original `DisplayObjectContainer`, up to the original
child count. If new DisplayObjects were inserted into the list
during iteration, we could miss some of the original DisplayObjects
in the list (as they are now at a greater position in the list).
To solve this, we now store the render list as an `Rc<Vec>`,
and use `Rc::make_mut` to modify it. See the comments
for more details.
With SWF version < 30, Context3D.configureBackBuffer throws
an error with a less informative message when the width/height
are out of range. Additionally, it seems to special case
the case width=0, height=0, antiAlias=0. enableDepthAndStencil=false,
and does *not* throw an error. This is relied on by Sniper Team.
The Flash Player 'Matrix3D.recompose' method throws exceptions under
certain circumstances with the "quaternion" orientation style.
I haven't yet figured this out yet, so I've marked that case as a stub.
All of the implementations are based on the OpenFL code, with some
tweaks to match Flash Player's behavior.
TextFields have a very unusual behavior - if they are selectable
and have `was_static`, they *block* the dispatch of mouse events when
they're targeted (not even the Stage will receive the event).
This only occurs when the TextField is actually targeted
(which requires mouseEnabled=true). With mouseEnabled=false,
the event will be dispatched with an ancestor as the target,
following the usual logic.
Also, TextFields now properly propagate mouse picks to
their parent if mouseEnabled=false. Previously, setting
mouseEnabled=false for a TextField made all mouse picks
cause a miss on it. This was the cause of the Turbo Kids
regression.
Fixes#10245
This can actually affect runtime behavior - if the return type is
declared as 'int', then an instance of a custom class will get
coerced to 0 when returned by the function.
'Plants vs Zombies Demo' relies on this - it has a function which
incorrectly returns an object instead of an array index, but the
value gets silently coerced to 0 under Flash Player.
This is based on URLLoader, and doesn't actualy 'stream' data -
it all becomes available once the request finishes. However, this
is good enough to get Sniper Team working.
We now run all of the completion logic (including adding
the new DisplayObject as a child) in `Loader::movie_loader_complete`.
Previously, some of this logic was run from `Loader::preload_tick`,
which meant that loaded images did not have the logic run.
Also, `BitmapData` and `Bitmap` instances (with corresponding AVM2
objects) are now properly constructed for loaded images.
In a previous PR, I introduced an optimization that used
`copy_texture_to_texture` to copy directly from a BitmapData GPU
texture to a Stage3D GPU texture.
Unfortunately, this optimization is incorrect. A BitmapData GPU
texture can be modified at any time by normal AVM2 code - in
particular, in might be modified before we submit the encoded
`copy_texture_to_texture` command. This shows up in Sniper Team,
which re-uses BitmapData objects for multiple distinct textures.
The previous 'optimization' resulted in the wrong BitmapData contents
getting uploaded to a texture (since it was changed before the copy
command was submitted).
When multisampling is enabled, we should create a new multisampled texture,
and use the existing texture as the resolve buffer. We also need to
call `update_has_depth_texture` to keep our pipeline aware of whether
or not we currently have a depth buffer attached.
Makes progress on #10641 (it has a stack overflow after
this PR, due to an unrelated issue).
wgpu requires buffer copy sizes and offsets to be 4-byte aligned.
Unfortunately, ActionScript can perform 2-byte aligned uploads
into an IndexBuffer3D.
To support this, we now keep a copy of the IndexBuffer3D on the CPU.
When performing an upload to the buffer, we round the offset down
and the size up to the nearest 4-byte aligned value. The cpu buffer
is used to fill out the write with existing data, so that we don't
corrupt the contents of the GPU buffer.
To avoid introducing a new RefCell, I've changed IndexBuffer3D
to use a `Box` instead of an `Rc` to store the trait object.
This allows us to pass a mutable reference down to the backend.
Early class construction is tricky - `Object` defines properties
that need to get copied into subclass instance vtables, but `Class`
defines `prototype`, which needs to be copied into the *class* vtable
of `Object`.
To accomplish this, I've split out instance vtable initialization
into a separate `init_instance_vtable`. We call
`object_class.init_instance_vtable` before
`class_class.init_instance_vtable`, but do things in the opposite
order for `into_finished_class` (`class_class.into_finished_class` is
called before `object_class.into_finished_class`)
It's possible to have a DefineSprite tag with multiple frames,
but with a corresponding SymbolClass that directly extends
`Sprite` (and therefore does *not* extend `MovieClip`). When this
happens, Flash Player stops after the first frame.
Doing `super.someNonGetter` gives you back a function object.
We were previously attempting to call normal methods as though
they were getters. Additionally, we were failing to properly
get the property from the superclass vtable.
If a SWF contains multiple DefineFont tags with the same
font name (but different font IDs), the first tag will win
when a font is looked up by *name*. This affects the behavior
of EditText objects, which can have embedded HTML like
`<font face="MyFontName">` which performs a font lookup by name.
This fixes Fancy Pants World 4 Part 3, which contains two
DefineFont3 tags with the name FancyFont. The second font is
missing many glyphs, so using it causes us to be unable to
render the squiggle and life count text.