core: Complete MovieClip error state & Change uncompressed_len to i32
Previously, the MovieClip error state contained one TODO in order to be completely implemented: The HeaderExt variable uncompressed_len needs to be -1 in the error state, but its type has been u32. The type has now been changed to i32, and the variable is set to -1 in the default_error_header function. Therefore, the MovieClip error state is now fully implemented. Other connected functions and variables like SwfMovie::uncompressed_len or MovieClip::total_bytes have been adjusted to this type change. Code has been adjusted if needed where this value is used.
This commit is contained in:
parent
893052c2a6
commit
687c0e7516
|
@ -235,7 +235,7 @@ impl<'gc> LoaderInfoObject<'gc> {
|
||||||
let should_complete = match self.0.read().loaded_stream {
|
let should_complete = match self.0.read().loaded_stream {
|
||||||
Some(LoaderStream::Swf(_, root)) => root
|
Some(LoaderStream::Swf(_, root)) => root
|
||||||
.as_movie_clip()
|
.as_movie_clip()
|
||||||
.map(|mc| mc.loaded_bytes() >= mc.total_bytes())
|
.map(|mc| mc.loaded_bytes() as i32 >= mc.total_bytes())
|
||||||
.unwrap_or(true),
|
.unwrap_or(true),
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1205,13 +1205,13 @@ impl<'gc> MovieClip<'gc> {
|
||||||
self.0.read().frames_loaded()
|
self.0.read().frames_loaded()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn total_bytes(self) -> u32 {
|
pub fn total_bytes(self) -> i32 {
|
||||||
// For a loaded SWF, returns the uncompressed size of the SWF.
|
// For a loaded SWF, returns the uncompressed size of the SWF.
|
||||||
// Otherwise, returns the size of the tag list in the clip's DefineSprite tag.
|
// Otherwise, returns the size of the tag list in the clip's DefineSprite tag.
|
||||||
if self.is_root() {
|
if self.is_root() {
|
||||||
self.movie().uncompressed_len()
|
self.movie().uncompressed_len()
|
||||||
} else {
|
} else {
|
||||||
self.tag_stream_len() as u32
|
self.tag_stream_len() as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1220,10 +1220,10 @@ impl<'gc> MovieClip<'gc> {
|
||||||
let progress_read = read.static_data.preload_progress.read();
|
let progress_read = read.static_data.preload_progress.read();
|
||||||
if progress_read.next_preload_chunk == u64::MAX {
|
if progress_read.next_preload_chunk == u64::MAX {
|
||||||
// u64::MAX is a sentinel for load complete
|
// u64::MAX is a sentinel for load complete
|
||||||
return self.total_bytes();
|
return max(self.total_bytes(), 0) as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let swf_header_size = self.total_bytes() - self.tag_stream_len() as u32;
|
let swf_header_size = max(self.total_bytes(), 0) as u32 - self.tag_stream_len() as u32;
|
||||||
|
|
||||||
swf_header_size + progress_read.next_preload_chunk as u32
|
swf_header_size + progress_read.next_preload_chunk as u32
|
||||||
}
|
}
|
||||||
|
|
|
@ -1531,7 +1531,7 @@ impl Player {
|
||||||
.root_clip()
|
.root_clip()
|
||||||
.and_then(|root| root.as_movie_clip())
|
.and_then(|root| root.as_movie_clip())
|
||||||
{
|
{
|
||||||
let was_root_movie_loaded = root.loaded_bytes() == root.total_bytes();
|
let was_root_movie_loaded = root.loaded_bytes() as i32 == root.total_bytes();
|
||||||
did_finish = root.preload(context, limit);
|
did_finish = root.preload(context, limit);
|
||||||
|
|
||||||
if let Some(loader_info) = root.loader_info().filter(|_| !was_root_movie_loaded) {
|
if let Some(loader_info) = root.loader_info().filter(|_| !was_root_movie_loaded) {
|
||||||
|
|
|
@ -150,7 +150,7 @@ impl SwfMovie {
|
||||||
/// Construct a movie based on a loaded image (JPEG, GIF or PNG).
|
/// Construct a movie based on a loaded image (JPEG, GIF or PNG).
|
||||||
pub fn from_loaded_image(url: String, length: usize) -> Self {
|
pub fn from_loaded_image(url: String, length: usize) -> Self {
|
||||||
let mut movie = Self {
|
let mut movie = Self {
|
||||||
header: HeaderExt::default_with_uncompressed_len(length as u32),
|
header: HeaderExt::default_with_uncompressed_len(length as i32),
|
||||||
data: vec![],
|
data: vec![],
|
||||||
url,
|
url,
|
||||||
loader_url: None,
|
loader_url: None,
|
||||||
|
@ -235,7 +235,7 @@ impl SwfMovie {
|
||||||
self.compressed_len
|
self.compressed_len
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uncompressed_len(&self) -> u32 {
|
pub fn uncompressed_len(&self) -> i32 {
|
||||||
self.header.uncompressed_len()
|
self.header.uncompressed_len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ pub struct FileResults {
|
||||||
|
|
||||||
/// The uncompressed length of the SWF file.
|
/// The uncompressed length of the SWF file.
|
||||||
#[serde(rename = "Uncompressed Length")]
|
#[serde(rename = "Uncompressed Length")]
|
||||||
pub uncompressed_len: Option<u32>,
|
pub uncompressed_len: Option<i32>,
|
||||||
|
|
||||||
/// Any errors encountered while testing.
|
/// Any errors encountered while testing.
|
||||||
#[serde(rename = "Error")]
|
#[serde(rename = "Error")]
|
||||||
|
|
|
@ -166,7 +166,7 @@ pub fn decompress_swf<'a, R: Read + 'a>(mut input: R) -> Result<SwfBuf> {
|
||||||
header,
|
header,
|
||||||
file_attributes,
|
file_attributes,
|
||||||
background_color,
|
background_color,
|
||||||
uncompressed_len,
|
uncompressed_len: uncompressed_len as i32,
|
||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
})
|
})
|
||||||
|
|
|
@ -97,7 +97,7 @@ pub struct HeaderExt {
|
||||||
pub(crate) header: Header,
|
pub(crate) header: Header,
|
||||||
pub(crate) file_attributes: FileAttributes,
|
pub(crate) file_attributes: FileAttributes,
|
||||||
pub(crate) background_color: Option<SetBackgroundColor>,
|
pub(crate) background_color: Option<SetBackgroundColor>,
|
||||||
pub(crate) uncompressed_len: u32,
|
pub(crate) uncompressed_len: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HeaderExt {
|
impl HeaderExt {
|
||||||
|
@ -119,12 +119,12 @@ impl HeaderExt {
|
||||||
header: Header::default_with_swf_version(0),
|
header: Header::default_with_swf_version(0),
|
||||||
file_attributes: Default::default(),
|
file_attributes: Default::default(),
|
||||||
background_color: None,
|
background_color: None,
|
||||||
uncompressed_len: 0, // TODO: This needs to be -1
|
uncompressed_len: -1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the header for a loaded image (JPEG, GIF or PNG).
|
/// Returns the header for a loaded image (JPEG, GIF or PNG).
|
||||||
pub fn default_with_uncompressed_len(length: u32) -> Self {
|
pub fn default_with_uncompressed_len(length: i32) -> Self {
|
||||||
let header = Header {
|
let header = Header {
|
||||||
compression: Compression::None,
|
compression: Compression::None,
|
||||||
version: 0,
|
version: 0,
|
||||||
|
@ -199,7 +199,7 @@ impl HeaderExt {
|
||||||
|
|
||||||
/// The length of the SWF after decompression.
|
/// The length of the SWF after decompression.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn uncompressed_len(&self) -> u32 {
|
pub fn uncompressed_len(&self) -> i32 {
|
||||||
self.uncompressed_len
|
self.uncompressed_len
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -303,7 +303,7 @@ struct MovieMetadata {
|
||||||
background_color: Option<String>,
|
background_color: Option<String>,
|
||||||
is_action_script_3: bool,
|
is_action_script_3: bool,
|
||||||
#[serde(rename = "uncompressedLength")]
|
#[serde(rename = "uncompressedLength")]
|
||||||
uncompressed_len: u32,
|
uncompressed_len: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An opaque handle to a `RuffleInstance` inside the pool.
|
/// An opaque handle to a `RuffleInstance` inside the pool.
|
||||||
|
|
Loading…
Reference in New Issue