Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sf::cursor.loadFromPixels doesn't work. #2066

Closed
Neko-Box-Coder opened this issue Apr 10, 2022 · 10 comments
Closed

sf::cursor.loadFromPixels doesn't work. #2066

Neko-Box-Coder opened this issue Apr 10, 2022 · 10 comments

Comments

@Neko-Box-Coder
Copy link

Neko-Box-Coder commented Apr 10, 2022

sf::cursor.loadFromPixels doesn't work.

sf::cursor.loadFromPixels is not showing anything (invisible cursor) despite it being set and returned true.

Note that this works on 2.5.1 (Monochrome) but not 3.0.0 (latest snapshot) at least on my machine, any confirmation on other Linux machines will be appreciated.

If there's anything needed, just message me and I will replay asap.

Your environment

  • Arch (5.15.28-1 kernel) with Xorg
  • Latest snapshot (Date of issue)
  • GCC (Unix) with CMake
  • set(SFML_STATIC_LIBRARIES TRUE)

Steps to reproduce

#include <iostream> 
#include "SFML/Graphics.hpp"
#include "SFML/Window.hpp"

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    sf::Cursor SFMLCursor;

    uint8_t TempCursor[256] =
    {
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,
        0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255,       0, 0, 0, 255
    };


    if(!SFMLCursor.loadFromPixels(&TempCursor[0], sf::Vector2u(8, 8), sf::Vector2u()))
        std::cout<<"Failed to load cursor\n";

    // if(!SFMLCursor.loadFromSystem(sf::Cursor::Type::Hand))
    //     std::cout<<"Failed to load cursor\n";

    window.setMouseCursor(SFMLCursor);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear(sf::Color(255, 255, 255, 255));
        window.draw(shape);
        window.display();
    }

    return 0;
}

Expected behavior

It should show the cursor as a black 8x8 image.

Actual behavior

The cursor is invisible instead.

@eXpl0it3r
Copy link
Member

Can you give the 2.6.x branch a try, so we can check whether it's a regression in SFML 3 or already came with SFML 2.6?

@Neko-Box-Coder
Copy link
Author

I just tried 2.6.x from the snapshot. It is the same result

@eXpl0it3r
Copy link
Member

The same bad (3.0.0 behavior) or same good (2.5.1 behavior) result? 😄

@Neko-Box-Coder
Copy link
Author

Yeah sorry, I mean same result as 3.0.0 haha.

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.6.0 via automation Apr 11, 2022
@eXpl0it3r eXpl0it3r added this to the 2.6 milestone Apr 11, 2022
@ChrisThrasher
Copy link
Member

Are you able to bisect the commit history to find the exact commit which introduced the problem? That would be really helpful to know.

@texus
Copy link
Contributor

texus commented Apr 11, 2022

It looks like the bug was introduced in e0f2356
The version before that commit still showed the cursor, and with that commit the cursor is no longer visible.

@kimci86
Copy link
Contributor

kimci86 commented Apr 11, 2022

This fixes the issue for me (branch 2.6.x):

diff --git a/src/SFML/Window/Unix/CursorImpl.cpp b/src/SFML/Window/Unix/CursorImpl.cpp
index d0d51300..f2cfdf80 100644
--- a/src/SFML/Window/Unix/CursorImpl.cpp
+++ b/src/SFML/Window/Unix/CursorImpl.cpp
@@ -80,10 +80,10 @@ bool CursorImpl::loadFromPixelsARGB(const Uint8* pixels, Vector2u size, Vector2u
     const std::size_t numPixels = size.x * size.y;
     for (std::size_t pixelIndex = 0; pixelIndex < numPixels; ++pixelIndex)
     {
-        cursorImage->pixels[pixelIndex] = static_cast<Uint8>(pixels[pixelIndex * 4 + 2] +
-                                                            (pixels[pixelIndex * 4 + 1] << 8) +
-                                                            (pixels[pixelIndex * 4 + 0] << 16) +
-                                                            (pixels[pixelIndex * 4 + 3] << 24));
+        cursorImage->pixels[pixelIndex] = static_cast<Uint32>(pixels[pixelIndex * 4 + 2] +
+                                                              (pixels[pixelIndex * 4 + 1] << 8) +
+                                                              (pixels[pixelIndex * 4 + 0] << 16) +
+                                                              (pixels[pixelIndex * 4 + 3] << 24));
     }
 
     // Create the cursor.

@eXpl0it3r
Copy link
Member

@Neko-Box-Coder, can you confirm that the merge fix (#2073) onto 2.6.x fixes the problem?

SFML 2.6.0 automation moved this from WIP to Done Apr 13, 2022
@Neko-Box-Coder
Copy link
Author

@eXpl0it3r Thanks a lot, I can confirm it fixed the problem. Will this be merged to master at some point?

@eXpl0it3r
Copy link
Member

Yes, might wait for some other 2.6.x PR, but if those don't come through soon, then I'll do another back merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.6.0
  
Done
Development

No branches or pull requests

5 participants