Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: weird behavior from my color picker (SFML & TGUI) [topic paused]  (Read 3224 times)

0 Members and 1 Guest are viewing this topic.

Ryder17z

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hello. I have built a color picker, but it doesn't work consistently, sometimes these things happen:



The selected elements should update correctly according to the color picker but sometimes they don't.

Code has been ripped out from a larger project and the issue remains.


I'm not sure why it behaves like this, any help would be appreciated. A repo with the project can be found here:

https://bitbucket.org/Ryder17z/color-picker-sfml-tgui/

I'm using visual studio but any other IDE should work as long as linker settings are adjusted appropriately
« Last Edit: April 01, 2020, 12:19:29 pm by Ryder17z »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: weird behavior from my color picker (SFML & TGUI)
« Reply #1 on: March 26, 2020, 08:35:33 am »
What does "doesn't work correctly" mean exactly?

Can you describe the actual result and the expected result?
Plus can you narrow it down in your project a bit more? I don't intend to read your whole project, just to help with this bug of yours. ;)

As I don't know TGUI, is this a standard TGUI element? Maybe asking on the TGUI forum will be more efficient.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ryder17z

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: weird behavior from my color picker (SFML & TGUI)
« Reply #2 on: March 31, 2020, 11:03:07 am »
What does "doesn't work correctly" mean exactly?

Can you describe the actual result and the expected result?
See screenshots. Sometimes i get weird a weird color and i can't figure out why that happens.

Plus can you narrow it down in your project a bit more? I don't intend to read your whole project, just to help with this bug of yours. ;)
Pretty much anything irrelevant to this issue has been stripped out already. sorry, but I don't have much more that i can remove.


As I don't know TGUI, is this a standard TGUI element? Maybe asking on the TGUI forum will be more efficient.

TGUI does not have a colorpicker element, it has slider, checkbox, textlabel, buttons, etc.

Hence the need to write my own.



I can try to explain better though;

I'm taking an int from each of my 3 scrollbars and feed them into HSV() to construct a color, i send that color through HSVToRGB() to update my chosen element

Both functions are inside: https://bitbucket.org/Ryder17z/color-picker-sfml-tgui/src/master/src/ColorHeader.h


I do everything related inside https://bitbucket.org/Ryder17z/color-picker-sfml-tgui/src/master/src/main.cpp
lines 205-267

the rest is pretty standard stuff, init window, load resources (in this case gui element styling, respective default values)


I hope that is enough details

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: weird behavior from my color picker (SFML & TGUI)
« Reply #3 on: March 31, 2020, 11:15:45 am »
See screenshots. Sometimes i get weird a weird color and i can't figure out why that happens.
You assume that everyone understands what your screenshot is showing, but you need to explain it in words, so we can understand what you expect and what is actually happening.

Have you debugged your code? If I understand it correctly, this doesn't really seem like an issue related to SFML or TGUI but something in your color picking code.
Going through your code step by step should reveal potential logical errors.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ryder17z

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: weird behavior from my color picker (SFML & TGUI)
« Reply #4 on: March 31, 2020, 02:14:11 pm »
You assume that everyone understands what your screenshot is showing, but you need to explain it in words, so we can understand what you expect and what is actually happening.
I expect the color indicated using the marker in the gradient to set the color to the checked elements to the left

Have you debugged your code? If I understand it correctly, this doesn't really seem like an issue related to SFML or TGUI but something in your color picking code.
Going through your code step by step should reveal potential logical errors.

I am debugging it but i'm not seeing where the issue is coming from.

Here's an example, color is suddenly white, instead of something very red:

Quote
input (X)sat:20 (Y) vel:13 ColorHue:0
old color: R:244 G:228 B:228
new color: R:243 G:247 B:247



texus

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • TGUI
    • Email
Re: weird behavior from my color picker (SFML & TGUI)
« Reply #5 on: March 31, 2020, 07:42:54 pm »
You should really reduce code to a minimum if you want people to help you find the issue. It takes too much time for someone who doesn't know the code to get started with it. The code isn't minimal at all: it uses plog, is spread over multiple files and contains many unnecessary things. Why do I need to press a button and check a checkbox before I can start trying something? If it is not related then it should be removed, the contents of the child window should just be the contents of the main window. If it would have been related, then it should explicitly be said so as it would help narrowing the issue.

Do the scrollbars have any influence on the issue for example? Print the scrollbar values when the issue occurs and hardcode these values instead of getting them from the scrollbars. If the issue still occurs, then the scrollbars can be removed. If it doesn't occur when hardcoding the values then at least you get some more information as to where in the code to look.

Your code has so many weird things going on that may or may not be related to your issue that it is hard to even pinpoint the issue for someone who doesn't know the code. Printing the ColorHue variable for example shows that you are trying to store 360 values in a 8-bit variable. You seem to know this already because it has a comment next to it that you should prevent overflow, but you should probably fix this first as these kind of issues might contribute to the real issue or at least waste time of people trying to look for the issue. You also imply in your previous post that HSV(0, 20, 13) would be bright red, but it is actually much closer to black if you look it up. Even the debug print is confusing since you print the values in S, V, H order instead of H, S, V. The image you use is also a bit confusing: Normally white is at the left side (because an S value of 0 gives you white to black, with no hue).

Values in HSV are usually limited to (360, 100%, 100%), but it doesn't seem to be the case in your code (and the magic numbers don't make it easier to understand what the code is actually using). The fact that the HSV class stores its values as doubles made me think that it might use values between 0 and 1 for S and V, and looking at the ColorTest function at the bottom of ColorHeader.h shows that the assumption was right. Yet your code stores them as uint8_t with values from 0 to 255. If this isn't the main issue then at least it is part of it.

If your input is HSV(0, 20, 13) and your output is RGB(243, 247, 247), like you showed in your last post, and you believe that the given output is incorrect for the provided input then you could have minimized your code to this:
int main()
{
    HSV hsv = HSV(0, 20, 13);
    RGB rgb = HSVToRGB(hsv);
    std::cout << (int)rgb.R << " " << (int)rgb.G << " " << (int)rgb.B << std::endl;
}

That is how much you could have reduced the code. And then you probably would have been able to find the issue yourself.
Changing the HSV parameters to (0, 0.2, 0.13) does print the correct RGB values in this code.
If there are other issues in the code then at least this one would be dealt with and you can handle them one at a time by minimizing the code around some issue instead of trying to fix them all at once.
TGUI: C++ SFML GUI

Ryder17z

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: weird behavior from my color picker (SFML & TGUI)
« Reply #6 on: April 01, 2020, 12:18:55 pm »
Apologies. i've been rushing things. I'll get back to this when i have a decent amount of time to work on it.

Thanks, i'll go through everything at a better pace and hopefully find the issue.


consider the project put on ice for a little while.