openfl / lime

A foundational Haxe framework for cross-platform development
https://lime.openfl.org/
MIT License
754 stars 369 forks source link

Fails on Firefox, works on Chromium #521

Closed raould closed 9 years ago

raould commented 9 years ago

Ubuntu 14.04 lts x86, FF 39.0, just upgraded to lime 2.5.2, openfl 3.2.0, haxe 3.2.0. Trying to make something using HaxePunk. Same problem that I saw in lime 2.4.9 where things work ok in Chromium, but the non-tilemap sprites do not appear in Firefox.

IndexSizeError: Index or size is negative or greater than the allowed amount

on this line of code:

    if(sourceImage.buffer.get_src() != null) image.buffer.__srcContext.drawImage(sourceImage.buffer.get_src(),sourceRect.x + sourceImage.offsetX | 0,sourceRect.y + sourceImage.offsetY | 0,sourceRect.width | 0,sourceRect.height | 0,destPoint.x + image.offsetX | 0,destPoint.y + image.offsetY | 0,sourceRect.width | 0,sourceRect.height | 0);

in this method:

lime_graphics_utils_ImageCanvasUtil.copyPixels = function(image,sourceImage,sourceRect,destPoint,alphaImage,alphaPoint,mergeAlpha) {
    if(mergeAlpha == null) mergeAlpha = false;
    if(destPoint.x >= image.width || destPoint.y >= image.height) return;
    if(alphaImage != null && alphaImage.get_transparent()) {
        if(alphaPoint == null) alphaPoint = new lime_math_Vector2();
        var tempData = image.clone();
        tempData.copyChannel(alphaImage,new lime_math_Rectangle(alphaPoint.x,alphaPoint.y,sourceRect.width,sourceRect.height),new lime_math_Vector2(sourceRect.x,sourceRect.y),lime_graphics_ImageChannel.ALPHA,lime_graphics_ImageChannel.ALPHA);
        sourceImage = tempData;
    }
    lime_graphics_utils_ImageCanvasUtil.sync(image);
    if(!mergeAlpha) {
        if(image.get_transparent() && sourceImage.get_transparent()) image.buffer.__srcContext.clearRect(destPoint.x + image.offsetX,destPoint.y + image.offsetY,sourceRect.width + image.offsetX,sourceRect.height + image.offsetY);
    }
    lime_graphics_utils_ImageCanvasUtil.sync(sourceImage);
    if(sourceImage.buffer.get_src() != null) image.buffer.__srcContext.drawImage(sourceImage.buffer.get_src(),sourceRect.x + sourceImage.offsetX | 0,sourceRect.y + sourceImage.offsetY | 0,sourceRect.width | 0,sourceRect.height | 0,destPoint.x + image.offsetX | 0,destPoint.y + image.offsetY | 0,sourceRect.width | 0,sourceRect.height | 0);
};
Tw1ddle commented 9 years ago

I'm also getting this error with dev HaxeFlixel, Firefox 39.0 on Windows 8.1 and 10, for those same haxelib versions. Latest Chrome and Opera are fine though.

Tw1ddle commented 9 years ago

@raould I added a check in ImageCanvasUtil copyPixels to make sure it didn't draw anything with width or height of 0 and that gets things rendering for me:

if (sourceImage.buffer.src != null) {

    // New check
    var width:Int = Math.floor(sourceRect.width);
    var height:Int = Math.floor(sourceRect.height);     
    if(width == 0 || height == 0) {
        return;
    }

    image.buffer.__srcContext.drawImage (sourceImage.buffer.src, Std.int (sourceRect.x + sourceImage.offsetX), Std.int (sourceRect.y + sourceImage.offsetY), Std.int (sourceRect.width), Std.int (sourceRect.height), Std.int (destPoint.x + image.offsetX), Std.int (destPoint.y + image.offsetY), Std.int (sourceRect.width), Std.int (sourceRect.height));

}

This is assuming it is this problem: http://stackoverflow.com/a/21608118/1333253