Problem using masks on Android

I’m using triangular shaped masks on two rectangles to form a corner of a wall. This is working just fine on the Corona emulator which is running on a Mac and it performs just fine on an iPhone 5 and iPad 3.

However, it is getting very bad results on Android (Samsung Galaxy 3) and it isn’t obvious to me what is causing it. I am following all the prescribed conventions, the mask size is a multiple of 4 and it has 4 pixels of black all the way around it.

The mask is a .bmp. I don’t know if that makes a difference. The masked object is from an image sheet which is a .png.

What I see is in places where I am using a mask the wall is really translucent… as in I can barely see it. I have determined that this is only occurring where a mask is being used.

I am willing to post some screen shots but I’m not sure where I would post it to link it here. Has anyone seen anything like this?

Without seeing your code, I can’t be certain, but it’s possible you’re running into an issue with the amount of nested masks. See the below thread for a bit more information:

https://forums.coronalabs.com/topic/60694-strange-bug-masks-and-nearby-text-objects

Ok, that changes the definition of nesting. According to that thread they don’t actually have to be inside of each other… which is what nesting typically means. I’ll have to go back through it and see how many masked objects there are in that location. (The location is a display group which holds two pieces of wall that are both masked.)

Thank you for the link.

Ok, I did some tests and I do not believe this is my problem, basically I made a few changes so that only one mask was in the group and it still isn’t right.

What appears to be happening is that the mask is being applied inverted. The part of the image covered by the black part of the mask is showing and the part in the white is not showing. I will try to put together some test code.

Here is a thread where the guy says he is seeing masks become inverted:

https://forums.coronalabs.com/topic/19010-759-nested-masks-on-androids-become-inverted/

So it seems that it has something to do with the image being nested. However, unless every masked object in the same scene is considered nested in the scene… I don’t understand how this relates to my problem other than the mask is becoming inverted as he describes.

I reproduced the circumstances that he says reveals the problem and the problem no longer occurs so apparently it can be fixed and may be a bug in Corona.

Hi Mark,

Can you reproduce this issue in a far more simplified code example, instead of the highly “function-ized” and module-ized version you post here? Meaning, can you show the issue occurring in a basic example of ~10 lines, using some basic images and masks, and then share that code? I trust that your code above is OK, but there are a lot of moving parts that may be affecting the outcome, and I would like to see if this is reproducable at a more basic level before determining if it’s a Corona bug or not.

Thanks,

Brent

Here is the mask used in this example:

http://www.legendofus.net/wp-content/uploads/2015/12/mask_corner_2.bmp

Here is sample code that will demonstrate the problem on either a Kindle Fire 7" or a Samsung Galaxy 3:

[lua]display.setStatusBar( display.HiddenStatusBar )

local centerX = display.contentCenterX

local centerY = display.contentCenterY

local location = display.newGroup()

location.x, location.y = centerX, centerY

local groundG = display.newGroup()

location:insert(groundG)

local wall1G = display.newGroup()

groundG:insert(wall1G)

local wall1 = display.newRect( wall1G, 0, 0, 40, 20 )

wall1:setFillColor(1, 0, 0)

wall1G.y = 10

local wall1Mask = graphics.newMask(“mask_corner_2.bmp”)

wall1:setMask(wall1Mask)

wall1.maskY = 2

wall1.maskScaleX = -1

local wall2G = display.newGroup()

groundG:insert(wall2G)

local wall2 = display.newRect( wall2G, 0, 0, 40, 20 )

wall2:setFillColor(0, 0, 1)

wall2G.rotation = 90

wall2G.x = -10

local wall2Mask = graphics.newMask(“mask_corner_2.bmp”)

wall2:setMask(wall2Mask)

wall2.maskY = 2[/lua]

Edit: as an additional observation, if you take the code above and remove one of the masks, the bug still occurs. If you remove one of the walls and it’s mask, the bug still occurs. This means it is simply connected to the object being way down inside of a bunch of groups.

I’m not sure if this is relevant but this guy had a similar problem:

https://forums.coronalabs.com/topic/30366-bug-nested-masks-cause-masked-images-to-be-invisible-on-galaxy-s3/page-2

I’m just cataloging it here because I still don’t have a clue what is causing it.

Ok, after messing with it some more, I discovered the root cause. Apparently this device does not like .bmp files. If you take the .bmp mask above and convert it to a .png, the Android device works as expected.

I tried this in the beginning, but at the time I converted the wrong .bmp mask… basically I thought it was using mask A when it was using mask B. I converted mask A to .png and it didn’t fix the problem for obvious reasons. Using the test program above, I was just being methodical and tried it again and it fixed it. #sorryaboutthemess

Without seeing your code, I can’t be certain, but it’s possible you’re running into an issue with the amount of nested masks. See the below thread for a bit more information:

https://forums.coronalabs.com/topic/60694-strange-bug-masks-and-nearby-text-objects

Ok, that changes the definition of nesting. According to that thread they don’t actually have to be inside of each other… which is what nesting typically means. I’ll have to go back through it and see how many masked objects there are in that location. (The location is a display group which holds two pieces of wall that are both masked.)

Thank you for the link.

Ok, I did some tests and I do not believe this is my problem, basically I made a few changes so that only one mask was in the group and it still isn’t right.

What appears to be happening is that the mask is being applied inverted. The part of the image covered by the black part of the mask is showing and the part in the white is not showing. I will try to put together some test code.

Here is a thread where the guy says he is seeing masks become inverted:

https://forums.coronalabs.com/topic/19010-759-nested-masks-on-androids-become-inverted/

So it seems that it has something to do with the image being nested. However, unless every masked object in the same scene is considered nested in the scene… I don’t understand how this relates to my problem other than the mask is becoming inverted as he describes.

I reproduced the circumstances that he says reveals the problem and the problem no longer occurs so apparently it can be fixed and may be a bug in Corona.

Hi Mark,

Can you reproduce this issue in a far more simplified code example, instead of the highly “function-ized” and module-ized version you post here? Meaning, can you show the issue occurring in a basic example of ~10 lines, using some basic images and masks, and then share that code? I trust that your code above is OK, but there are a lot of moving parts that may be affecting the outcome, and I would like to see if this is reproducable at a more basic level before determining if it’s a Corona bug or not.

Thanks,

Brent

Here is the mask used in this example:

http://www.legendofus.net/wp-content/uploads/2015/12/mask_corner_2.bmp

Here is sample code that will demonstrate the problem on either a Kindle Fire 7" or a Samsung Galaxy 3:

[lua]display.setStatusBar( display.HiddenStatusBar )

local centerX = display.contentCenterX

local centerY = display.contentCenterY

local location = display.newGroup()

location.x, location.y = centerX, centerY

local groundG = display.newGroup()

location:insert(groundG)

local wall1G = display.newGroup()

groundG:insert(wall1G)

local wall1 = display.newRect( wall1G, 0, 0, 40, 20 )

wall1:setFillColor(1, 0, 0)

wall1G.y = 10

local wall1Mask = graphics.newMask(“mask_corner_2.bmp”)

wall1:setMask(wall1Mask)

wall1.maskY = 2

wall1.maskScaleX = -1

local wall2G = display.newGroup()

groundG:insert(wall2G)

local wall2 = display.newRect( wall2G, 0, 0, 40, 20 )

wall2:setFillColor(0, 0, 1)

wall2G.rotation = 90

wall2G.x = -10

local wall2Mask = graphics.newMask(“mask_corner_2.bmp”)

wall2:setMask(wall2Mask)

wall2.maskY = 2[/lua]

Edit: as an additional observation, if you take the code above and remove one of the masks, the bug still occurs. If you remove one of the walls and it’s mask, the bug still occurs. This means it is simply connected to the object being way down inside of a bunch of groups.

I’m not sure if this is relevant but this guy had a similar problem:

https://forums.coronalabs.com/topic/30366-bug-nested-masks-cause-masked-images-to-be-invisible-on-galaxy-s3/page-2

I’m just cataloging it here because I still don’t have a clue what is causing it.

Ok, after messing with it some more, I discovered the root cause. Apparently this device does not like .bmp files. If you take the .bmp mask above and convert it to a .png, the Android device works as expected.

I tried this in the beginning, but at the time I converted the wrong .bmp mask… basically I thought it was using mask A when it was using mask B. I converted mask A to .png and it didn’t fix the problem for obvious reasons. Using the test program above, I was just being methodical and tried it again and it fixed it. #sorryaboutthemess