Topics

Problem with ellipsefill on Android using BBCSDL 1.00a

Jon Welch
 

I have just installed the latest BBCSDL 1.00a on my Samsung S7 phone and tried to run the new ellipses.bbc example program.

Rather than get the filled ellipses as per running it on Windows or Linux, the entire background of the screen flashed different colours, 8 outline ellipses were drawn and then the program hung. 

If I comment out the call to the ellipsefill procedure, the program draws infinite outline ellipses as expected.

Unfortunately, I am not familiar enough with the code in the ellipse.bbc library to debug this further.

Richard Russell
 

On Tue, Feb 5, 2019 at 12:05 PM, Jon Welch wrote:
Unfortunately, I am not familiar enough with the code in the ellipse.bbc library to debug this further.
The demo works fine on my Samsung Galaxy Tab S2, but I have seen this effect myself on other devices.  It probably arises from your phone using a restricted colour palette (whereas desktop PCs and iOS devices tend to use full 24-bit RGB colour, Android devices often use 16-bit e.g. RGB565).  The result of this is that the 'flood fill to foreground' (PLOT 143) can fail because the colour it is looking for doesn't exist, because it cannot be represented in 16-bits!

You can experiment with changing the colour it 'flood fills' to, but there is no guarantee of success and it could just as easily stop it working on a different device! That colour is set in the fifth line from the bottom of the library:

      SYS "SDL_SetRenderDrawColor",@memhdc%,0,0,20,&FF

Try changing the 20 to something larger (say 30 or 40) to see if it makes any difference.  As you will appreciate the 'filled ellipses' are a kludge anyway because using a flood fill is not a very satisfactory method, not least because it is so slow.  But I'm stuck with the SDL2_gfx library as the means of drawing 2D graphics and that has no filled ellipse capability at all.

It is unfortunate that the SDL2_gfx library is so limited (and what it does do it does poorly).  It's why BBCSDL has no support for drawing segments, or circles/ellipses/arcs with a specified line thickness, or polylines etc.  Only a week or so ago I was in email correspondence with its author; I think he recognises some of its limitations but he confirmed that he has no intentions of improving it.  In an ideal world I'd like to ditch SDL2_gfx entirely in favour of a better 2D graphics library, bit I don't know of one.

Jon Welch
 

I have tried setting the colour to 30 and 40 as you suggest but I still get the same problem.

I will experiment more and report back if I get it working.

Many thanks for your fast response.

Richard Russell
 

On Tue, Feb 5, 2019 at 02:00 PM, Jon Welch wrote:
I will experiment more and report back if I get it working.
Out of interest, what does 'getri.bbc' report for the 'Pixel format' and 'BitsPerPixel'?  I presume that you're not actually wanting to use filled, angled, ellipses in a 'real' application?  They are rarely needed, in my experience, and best avoided.  Axis-aligned ellipses (using the regular ELLIPSE and ELLIPSE FILL) statements should work reliably.

Richard Russell
 

On Tue, Feb 5, 2019 at 02:49 PM, Richard Russell wrote:
Out of interest, what does 'getri.bbc' report for the 'Pixel format' and 'BitsPerPixel'?
Another test which might be of value is to try 'normal' plotting rather than the exclusive-or plotting that the ellipses.bbc example uses.  That is, to change GCOL 3,RND(15) to GCOL 0,RND(15) . That will bypass many of the messy SDL API calls in the ellipse library, and allow you to concentrate on the failing flood fill itself.  Incidentally, does the jigsaw.bbc example (in the games directory) work on your phone?  That makes extensive use of flood-fills so might be expected to fail too if that is where the problem lies.

Jon Welch
 

The Pixel format is &15151002 (RGB565) and the BitsPerPixel is 16

Jon Welch
 

Changing to GCOL 0,RND(15) exhibits the same background flash but this time, the ellipses are erased after each background flash so only the last one is visible.

The jigsaw game seems to work fine.

I will continue to investigate and report back.

Thanks for your continued support.

Richard Russell
 

On Tue, Feb 5, 2019 at 08:03 PM, Jon Welch wrote:
The Pixel format is &15151002 (RGB565) and the BitsPerPixel is 16
There's no reason why that shouldn't work fine.  It's the same as most (if not all) of my Android devices.

Richard Russell
 

On Tue, Feb 5, 2019 at 08:08 PM, Jon Welch wrote:
I will continue to investigate and report back.
I will be fascinated to learn what you finally discover the cause to be (if you do).  I can think of only three ways in which a 'flood fill to foreground' can fail:

1. The 'bounding curve' isn't precisely the same colour as the foreground colour you have specified.
2. The bounding curve has a 'hole' through which the flood fill can leak (it only needs to be one pixel).
3. The 'starting point' isn't where you intended it to be (i.e. outside rather than inside the bounding curve).

It's quite hard to understand how any of those could vary between different Android devices, especially devices sharing the same pixel format, yet that is what is happening.  I can see the attraction of programming for devices that have 'standardised' hardware, such as Apple Macs or iPhones or Xboxes, when you can be pretty confident that if your code works on one it will work on them all.  Not so Windows PCs or Android devices!

Richard Russell
 

On Tue, Feb 5, 2019 at 10:53 PM, Richard Russell wrote:
2. The bounding curve has a 'hole' through which the flood fill can leak (it only needs to be one pixel).
To the extent that I have been able to analyze the problem here, it would appear that this is the cause.  The question then arises: why does the bounding curve (ellipse) have holes through which the flood-fill leaks, and why is it happening on your specific Android device but not generally?  I'm pretty confident that nothing in BBC BASIC is to blame, so I fear it may point to a bug in Samsung's implementation of OpenGL ES 1.1 on your Galaxy S7 phone.

Does anybody here have a Samsung Galaxy S8 or S9?  If so, can they please check whether the 'ellipses' demo works correctly or not?

Richard Russell
 

On Wed, Feb 6, 2019 at 05:58 PM, Richard Russell wrote:
why is it happening on your specific Android device but not generally?
That remains a mystery, but I've added a workaround to the ellipse library which should - if my limited understanding of what is happening is correct - force your device to conform!  Please install version 1.00b from the usual place (only the Android edition has changed) and let me know if it fixes the problem.

Jon Welch
 

Thanks for looking this further.

I only got as far as the colour being returned from the border@ellipse function was different between the windows and android version (probably due to my device only having 16 bit graphics). Windows returned FF000014 (when setting the colour to 20), but my device returned FF000010 instead. But setting the colour to 16 in the SetRenderDrawColor line still didn't work properly.

Anyway, I have just installed version 1.00b and it is a lot better in that the ellipses are now being filled but I am still getting a flashing screen background.

I will continue to investigate and report back.

Thanks again.

lettersquash <j.r.freestone@...>
 
Edited

Hi Richard and Jon,
Just a bit more info in case it's of help. I've installed the 1.00b since this last tweak on two Android devices. On my phone, cheap Chinese Homtom HT Pro3, with Android 5.1? (5.something anyway), I also get improved elipses, but with occasional ones (mainly near-horizontal aspect, but one or two near vertical) that fail and cause the background to flash when these come round to be drawn again. On my other device, a Galaxy Tab (model SM-T210) running Android 4.4.2, they are drawn perfectly. At least, I assume so, I haven't had time to actually read the code yet, but I'm guessing they aren't meant to stay on the screen forming a daisy shape - on this machine they are drawn, undrawn (or the screen is cleared, but presumably that wouldn't have failed and I saw you mention reversing colours with GCOL3...) and then the next drawn. On my phone, they're not undrawn, so you end up with a multi-coloured daisy. Very pretty. ;)

Before updating, my phone showed mostly outlines IIRC. I'm not sure I tried elipses.bbc on the Tab before this update.
HTH
JF

Richard Russell
 

On Thu, Feb 7, 2019 at 12:59 PM, lettersquash wrote:
I also get improved elipses, but with occasional ones (mainly near-horizontal aspect, but one or two near vertical) that fail and cause the background to flash when these come round to be drawn again.
It sounds as though the ellipses are not forming 'closed curves' at those specific angles, allowing the flood-fill to leak through.  I'm not aware of similar problems on any of the desktop platforms (Windows, MacOS, Linux, Raspberry Pi) or on iOS so this seems to be an Android-specific thing, albeit that it works perfectly on all the Android devices I have here (at least six).

I'd be interested to learn if it is failing on any relatively modern device, because even Android 5.1 (Lollipop) is pretty ancient.

Jon Welch
 

My S7 is running Android 8.0 and I can confirm that some ellipses have holes allowing the flood-fill to leak through.

Looks like it's a bug in the OS then :(

gav
 

Installed 1.00b on Samsung S9plus (Android 8.0.0) although it's due to do an update at 5am tonight.

When the ellipses are drawn at the horizontal angle the background changes to same colour as though the flood fill is leaking through.

Gavin

Sent from Samsung Mobile on O2

-------- Original message --------
From: Richard Russell <news@...>
Date: 06/02/2019 17:58 (GMT+00:00)
To: bb4w@groups.io
Subject: Re: [bb4w] Problem with ellipsefill on Android using BBCSDL 1.00a

On Tue, Feb 5, 2019 at 10:53 PM, Richard Russell wrote:
2. The bounding curve has a 'hole' through which the flood fill can leak (it only needs to be one pixel).
To the extent that I have been able to analyze the problem here, it would appear that this is the cause.  The question then arises: why does the bounding curve (ellipse) have holes through which the flood-fill leaks, and why is it happening on your specific Android device but not generally?  I'm pretty confident that nothing in BBC BASIC is to blame, so I fear it may point to a bug in Samsung's implementation of OpenGL ES 1.1 on your Galaxy S7 phone.

Does anybody here have a Samsung Galaxy S8 or S9?  If so, can they please check whether the 'ellipses' demo works correctly or not?

Richard Russell
 

On Thu, Feb 7, 2019 at 08:10 PM, Jon Welch wrote:
Looks like it's a bug in the OS then
But via what mechanism?  As you know the 2D 'drawing' routines (specifically the bezierColor function in this case) are in the SDL2_gfx library which is statically linked with BBCSDL, not part of Android.  So it's not clear to me how differences in the 'OS' can affect what pixels are plotted, even though the evidence would suggest that is exactly what is happening.

I do hope you will continue to investigate, perhaps by trying to devise a workaround if that is the only solution.  Out of curiosity, what is the effect of changing the number of line segments that are used to draw the Bezier curves (fifth parameter of bezierColor)?  Does increasing it from 3 to 4 (or more) make the problem better, worse, or no difference?  Can you tell (perhaps by changing the colours) whether the 'holes' are within the Bezier curves or between them?  If they are between them there is more opportunity for patching them.

If the problem cannot be fixed I will obviously have to remove the angled ellipse library from BBCSDL because it is not acceptable to include a library which isn't genuinely 'cross platform'.

Jon Welch
 

Changing the fifth parameter from 3 to 4 seems to have cured it. I no longer have any leaks !

Perhaps Gavin and others can confirm if their devices work with this change.

Thanks for all your help Richard in getting to the bottom of this problem.

Ken Orr
 

Hi Richard,

I am afraid it fails on "modern" android and Windows too.  I have attached screenshots of ellipses.bbc of my acer laptop  (Acer Aspire 7736z-4088) running Windows 10 on BBCSD20 1.00a  and of my Moto e4 (running Android 7.1.1) on BBCSDL20 1.00b.

Ken

On 07/02/2019 16:57, Richard Russell wrote:
On Thu, Feb 7, 2019 at 12:59 PM, lettersquash wrote:
I also get improved elipses, but with occasional ones (mainly near-horizontal aspect, but one or two near vertical) that fail and cause the background to flash when these come round to be drawn again.
It sounds as though the ellipses are not forming 'closed curves' at those specific angles, allowing the flood-fill to leak through.  I'm not aware of similar problems on any of the desktop platforms (Windows, MacOS, Linux, Raspberry Pi) or on iOS so this seems to be an Android-specific thing, albeit that it works perfectly on all the Android devices I have here (at least six).

I'd be interested to learn if it is failing on any relatively modern device, because even Android 5.1 (Lollipop) is pretty ancient.

Richard Russell
 

On Fri, Feb 8, 2019 at 07:19 AM, Jon Welch wrote:
Perhaps Gavin and others can confirm if their devices work with this change.
I see a post from him, but it's empty so we don't know one way or the other!

Thanks for all your help Richard in getting to the bottom of this problem.
Sadly we haven't got to the "bottom" of anything!  There's no 'science' in increasing the number of line segments, if it has an effect it's presumably a fluke and just as likely to make things worse rather than better.  If a couple more members report that it helps I'll release a new version with that change to make it easier for others to test.  But I'd need a lot of feedback before feeling confident enough to call it a fix, albeit an empirical one.