Skip to content

Commit

Permalink
avm2: Correctly fire textureReady event for asynchronous Texture up…
Browse files Browse the repository at this point in the history
…loads
  • Loading branch information
Lord-McSweeney authored and Aaron1011 committed Sep 30, 2023
1 parent 742ee40 commit bdc0985
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
19 changes: 16 additions & 3 deletions core/src/avm2/globals/flash/display3D/textures/Texture.as
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package flash.display3D.textures {
import flash.display.BitmapData;
import flash.events.Event;
import flash.utils.ByteArray;
import __ruffle__.stub_method;
import flash.utils.setTimeout;

public final class Texture extends TextureBase {
public native function uploadFromBitmapData(source:BitmapData, miplevel:uint = 0):void;
public native function uploadFromByteArray(data:ByteArray, byteArrayOffset:uint, miplevel:uint = 0):void;
public native function uploadCompressedTextureFromByteArray(data:ByteArray, byteArrayOffset:uint, async:Boolean = false):void;
public function uploadCompressedTextureFromByteArray(data:ByteArray, byteArrayOffset:uint, async:Boolean = false):void {
if (async) {
var self = this;
setTimeout(function() {
self.uploadCompressedTextureFromByteArrayInternal(data, byteArrayOffset);
self.dispatchEvent(new Event("textureReady"));
}, 0);
} else {
this.uploadCompressedTextureFromByteArrayInternal(data, byteArrayOffset);
}
}

private native function uploadCompressedTextureFromByteArrayInternal(data:ByteArray, byteArrayOffset:uint):void
}
}
}
11 changes: 1 addition & 10 deletions core/src/avm2/globals/flash/display3D/textures/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,14 @@ pub(super) fn do_compressed_upload<'gc>(
Ok(())
}

pub fn upload_compressed_texture_from_byte_array<'gc>(
pub fn upload_compressed_texture_from_byte_array_internal<'gc>(
activation: &mut Activation<'_, 'gc>,
this: Object<'gc>,
args: &[Value<'gc>],
) -> Result<Value<'gc>, Error<'gc>> {
let texture = this.as_texture().unwrap();
let data = args.get_object(activation, 0, "data")?;
let byte_array_offset = args.get_u32(activation, 1)? as usize;
let async_ = args.get_bool(2);
if async_ {
avm2_stub_method!(
activation,
"flash.display3D.textures.Texture",
"uploadCompressedTextureFromByteArray",
"with async"
);
}

if !matches!(texture.original_format(), Context3DTextureFormat::Bgra) {
avm2_stub_method!(
Expand Down

0 comments on commit bdc0985

Please sign in to comment.