kershner / screenBloom

Fake Ambilight for Philips Hue via Python
http://www.screenbloom.com
329 stars 48 forks source link

ZeroDivisionError #20

Closed s5zone closed 6 years ago

s5zone commented 7 years ago

Happened multiple times during the last days, mostly when starting a game

Parse Method: standard | Color Mode: average Updating [lamp name] -> Color: rgb(10, 10, 10) | Gamut: C | Bri: 1 Exception in thread Thread-2: Traceback (most recent call last): File "C:\Python27\Lib\threading.py", line 810, in __bootstrap_inner File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 26, in run File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 228, in run File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 160, in update_bulbs File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 198, in send_light_commands File "c:\programming\projects\hue_project\app\modules\hue_interface.py", line 94, in send_rgb_to_bulb File "c:\programming\projects\hue_project\app\modules\vendor\rgb_xy.py", line 234, in rgb_to_xy File "c:\programming\projects\hue_project\app\modules\vendor\rgb_xy.py", line 161, in get_xy_point_from_rgb ZeroDivisionError: float division by zero

kershner commented 7 years ago

Hey thanks for bringing this up. I actually had another user report this last week, haven't had a chance to dig into it just yet. Here's some info I've gathered so far (for posterity):

I want to say it seems to run into issue when the zone is not equally divisible by the number of lights. Example 3 lights with 1 or 4 zones. So if I do 3 zones for 3 lights it works, or 6 zones, or 9 zones.

Guessing it's a simple fix somewhere in the zone code, I just need to find the time to take a good look.

By the way...

If you could send me your screenbloom_config.cfg file that would be very helpful.

The file is located (on Windows): c:\Users\<your username>\AppData*\Roaming\screenbloom_config.cfg

*you will need to 'Show Hidden Files/Folders' to see the AppData directory

s5zone commented 7 years ago

Hi,

Thanks for the quick follow-up! In attachment you can find my cfg. I only have one zone for screenbloom as I have one bulb out of four activated for screenbloom (lightstrip) at my desk (so 1-1).

I would like to thank you as well for this awesome piece of software. It improved my general gaming experience by a lot!!! :-)

Greets, s5zone

2017-01-12 22:44 GMT+01:00 Tyler Kershner notifications@github.com:

Hey thanks for bringing this up. I actually had another user report this last week, haven't had a chance to dig into it just yet. Here's some info I've gathered so far (for posterity):

  • It's only caused by certain zone configurations. So you can probably mess around/tweak your zones a little bit and land on a configuration that doesn't throw the error.
  • From the other user who reported this:

I want to say it seems to run into issue when the zone is not equally divisible by the number of lights. Example 3 lights with 1 or 4 zones. So if I do 3 zones for 3 lights it works, or 6 zones, or 9 zones.

Guessing it's a simple fix somewhere in the zone code, I just need to find the time to take a good look. By the way...

If you could send me your screenbloom_config.cfg file that would be very helpful.

The file is located (on Windows): c:\Users\\AppData*\Roaming\screenbloom_config.cfg

*you will need to 'Show Hidden Files/Folders' to see the AppData directory

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/kershner/screenBloom/issues/20#issuecomment-272293469, or mute the thread https://github.com/notifications/unsubscribe-auth/AX7D6Va1yPOiUHOR2HkTgnmKHzalyYQTks5rRp7ZgaJpZM4Lh_iZ .

wtchappell commented 7 years ago

I've also been hitting this error.

Here's my config: http://pastebin.com/U7QP9J6f

wtchappell commented 7 years ago

I've hit this problem with zone mode disabled, and I've even hit this problem in party mode as well.

wtchappell commented 7 years ago
Party Mode!
Updating Desk Left -> Color: rgb(149, 48, 253) | Gamut: B | Bri: 4
Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Python27\Lib\threading.py", line 810, in __bootstrap_inner
  File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 26, in run
  File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 206, in run
  File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 176, in update_bulb_party
  File "c:\programming\projects\hue_project\app\modules\sb_controller.py", line 198, in send_light_commands
  File "c:\programming\projects\hue_project\app\modules\hue_interface.py", line 94, in send_rgb_to_bulb
  File "c:\programming\projects\hue_project\app\modules\vendor\rgb_xy.py", line 234, in rgb_to_xy
  File "c:\programming\projects\hue_project\app\modules\vendor\rgb_xy.py", line 161, in get_xy_point_from_rgb
ZeroDivisionError: float division by zero
wtchappell commented 7 years ago

I think I figured out part of it; I think this only happens or is at least more common when you use the alternate color for 'Off' instead of the default.

skercher commented 7 years ago

I have seen this error on MacOS Sierra.

When I turn on ZoneMode this error occurs. All other settings are left to default.

Time elapsed: 0.60 Updating Hue color lamp 1 -> Color: rgb(31, 25, 25) | Gamut: C | Bri: 223 Updating Hue color lamp 3 -> Color: rgb(31, 25, 25) | Gamut: C | Bri: 223 Updating Hue color lamp 2 -> Color: rgb(31, 25, 25) | Gamut: C | Bri: 223 Updating Hue color lamp 4 -> Color: rgb(31, 25, 25) | Gamut: B | Bri: 223 Updating Hue color spot 1 -> Color: rgb(31, 25, 25) | Gamut: B | Bri: 223 Updating Hue color lamp 5 -> Color: rgb(31, 25, 25) | Gamut: B | Bri: 223 Thread does not exist yet ERROR:main:Exception on /toggle-zone-state [POST] Traceback (most recent call last): File "flask/app.py", line 1817, in wsgi_app File "flask/app.py", line 1477, in full_dispatch_request File "flask/app.py", line 1381, in handle_user_exception File "flask/app.py", line 1475, in full_dispatch_request File "flask/app.py", line 1461, in dispatch_request File "", line 253, in toggle_zone_state File "modules/view_logic.py", line 145, in restart_check sb_controller.re_initialize() File "modules/sb_controller.py", line 135, in re_initialize results = img_proc.screen_avg(_screen) File "modules/img_proc.py", line 78, in screen_avg part_data = img_avg(part_img) File "modules/img_proc.py", line 42, in img_avg r_avg = r / n ZeroDivisionError: integer division or modulo by zero

skercher commented 7 years ago

Any idea how to fix this?

Thanks!

kershner commented 7 years ago

Haven't nailed down the exact cause yet but I'm getting close to a new release and will include some kind of dumb handling where it at least won't crash the program.

Any information about what was on your screen at the time of the error would be helpful so I can try to consistently reproduce it.

skercher commented 7 years ago

It appears if you create a zone with two cells it will throw the ZeroDivisionError. Zone needs to be at least 2x2. Thanks for the quick response!

wtchappell commented 7 years ago

@skercher - I think you have a different bug, as you have a different stack trace and the error isn't actually the same. The error I'm getting and that OP was getting is a floating point divide by zero, whereas yours is an integer exception from a different code path. My failure is coming from somewhere in the RGB -> XY conversion process, whereas yours looks like it's coming from somewhere in the code that actually makes the API calls to tell the bulbs what to do - or at least that's what the stacktrace looks like to me.

It's definitely still a problem that should be reported and fixed, but I think it's a different failure mode than what @s5zone and I have been seeing and probably deserves its own distinct issue. That said, it's not my code and I only briefly looked over it, so I could be full of crap. :)

That said, I can consistently trigger the floating point divide-by-zero exception by using the alternate color for 'off' regardless of whether zones are in use or not. I've had it happen in party mode, when it's not paying attention to the screen contents at all - but once I switch back to the default off color, everything works again.

kershner commented 7 years ago

@wtchappell - now that you mention the alternate black mode (and I think you did previously lol) I'm reminded of the chunk of code starting here. Also right below that I think maybe I already added handling for this error and it's just waiting to be released, haha. In any case, it's just a shallow bandaid over the problem.

The chunk I linked is basically this: if the computed brightness is less than 5, send the user's chosen black_rgb to be converted into an XY value instead of whatever was parsed by ScreenBloom. Looks like maybe the alternate black_rgb might be throwing the error when trying to be converted to XY.

If this assumption is correct, you should be able to reproduce the error consistently by opening up a completely dark image (something that will compute brightness to 5 or less). Here's one.

Also if the assumption is correct, then the problem will go away if you go back to the normal black color. You should also be able to avoid the error if you set your minimum brightness to 5 or higher.

I will test all of this stuff when I get home, but I just got to work as I type this haha. Let me know if you get there before me and what your results are.

Also - general feedback on the alternate black color feature? It's very old and kind of not great, IMO, I was thinking about removing it.

EDIT - just saw that you already confirmed using the normal black RGB solves the problem. That's great!

kershner commented 7 years ago

Released a new version at screenbloom.com which has the simple error handling and also removes the alternate black RGB setting. The program will at least not crash now when this error occurs.

Still experimenting and trying to consistently reproduce the error with zone mode so I will leave this issue open for now. Please share if you think you come across any new info.

kershner commented 6 years ago

Hey there -

Pretty sure I've narrowed down the cause of this issue and fixed it with this commit. You can grab a new version from screenbloom.com.

Closing for now, but please add another comment if you try the new version and still have the error and I will re-open the issue.