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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Herb

Pages: [1]
1
Graphics / Re: sf::Texture::~Texture() Crashes App On Exit
« on: November 17, 2016, 12:00:18 am »
Some code to help with how to use callbacks in a thread-safe manner:

typedef std::function<void(const std::string &data, bool success)> DownloadCallback;

struct DownloadItem {
    std::string data;
    DownloadCallback callback;
    bool success;
};

class Downloader {
public:
    void downloadItem(const std::string &itemUrl, const DownloadCallback &itemCallback) {
        _mutex.lock();
        // save itemUrl and itemCallback
        _mutex.unlock();
        // items get processed in background thread
    }

    void update() {
        DownloadItem item;
        bool gotItem = false;

        _mutex.lock();
        if (!_completedList.empty()) {
            item = _completedList[0];
            gotItem = true;
            _completedList.erase(_completedList.begin());
        }
        _mutex.unlock();

        if (gotItem) {
            item.callback(item.data, item.success);
        }
    }
private:
    // could use a queue instead of vector
    std::vector<DownloadItem> _completedList;
    std::mutex _mutex;
};

// UI thread
MyApp::run() {

    downloader.downloadItem("http://mysite.com/image.png", [&](const std::string &data, bool success) {
       
        if (success) {
            texture.loadFromMemory(data.c_str(), data.size());
        } else {
            sf::err() << "Failed to download image.\n";
        }
    });

    while (window.isOpen()) {

        // poll the downloader for completions
        downloader.update();

        // draw stuff
    }
}
 

2
Window / Re: No touch events on Surface devices
« on: October 21, 2016, 04:41:47 pm »
Thanks for the reply, Laurent.  *Please* add that to the documentation.  I spent about 16 hours on this unnecessarily.

3
Window / Re: No touch events on Surface devices
« on: October 21, 2016, 01:24:04 am »
Hi Mario,

Yes, I did step through with a debugger, and set breakpoints.  That is how I verified that only mouse events are coming in.  Besides events, the sf::Touch class is not returning any activity at all.  Am I missing an SFML setup or initialization call for touchscreen?

Thanks.

4
Window / No touch events on Surface devices
« on: October 20, 2016, 05:51:07 pm »
On a MS Surface 3, all touch events come in as mouse events:

- sf::EventType::MouseButtonPressed
- sf::EventType::MouseButtonReleased  <-- rarely receive this one
- sf::EventType::MouseMoved

This would be okay if the Released messages were reliable, but rarely receive them.

Also tried using sf::Touch::isDown() but it never returns true.  It's like SFML is completely unable to hook the touchscreen at all on these Surface devices.

I searched the forum before posting this.  Does anyone know of a reliable workaround?

Thanks.

Pages: [1]