Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
JoystickImpl: memory leak and strange wordings #660
I am on Mint / Linux, 64 bit and decided to try the latest code from the repo. Once I switched, I keep getting these ugly messages even for official examples:
Unable to get attribute 'idVendor'. Could not find parent USB device for joystick at index 0
It looks like it happens after this commit;
In addition to that Valgrind that never complained about SFML code now yells this:
Leak_DefinitelyLost|====|4,756 (448 direct, 4,308 indirect) bytes in 1 blocks are definitely lost in loss record 136 of 139|
changed the title from
Memory leak and strange wordings
JoystickImpl: memory leak and strange wordings
Jul 13, 2014
Well... I think the fix for the leak is quite obvious. udev_device_get_parent_with_subsystem_devtype overwrites dev with the parent device and when calling udev_device_unref the child device isn't properly unreferenced.
Documentation states that udev_device_get_parent_with_subsystem_devtype returns a device that is not referenced since it is attached to the child, hence the unreferencing is happening on the wrong device
As for why this triggers even when no joysticks are present... I have no idea. But I think the root of the problem lies in the detection of whether joysticks are present.
Can you check if there are any joystick nodes in /dev/input? They look something like /dev/input/js0 for node 0 and so on. SFML tries to open them one by one to check if any joysticks are present.
If it helps
May be this link can help as well: http://cgit.freedesktop.org/systemd/systemd/tree/src/udev/accelerometer/accelerometer.c?id=8fef0ff25c9fd7e5bb99d66f43c6357e4996a3cc
I am not sure about accelerometer for mobile phones.
Anyways, for me I've just made a small "hack" and disabled functionality in SFML if parent udev device is not defined. Also I've made that fix for memory leak that binary1248 referred to in 3rd comment. These 2 things solved all my issues, but I would be much more happier with a real fix from the team.
Last thing is about "getUdevAttributeUint". Hope someone will refactor this method as it doesn't make any sense for me to call it twice for "vendorId" and "productId" for each index and then call "udev_device_*" methods twice as well.
Yes, I have already planned to refactor several parts of the joystick code. It has been a mix of various contributions and is rather messy, sometimes it doesn't even conform to the SFML style. Unfortunately I'm quite busy at the moment, but I should have time to work on it in August.
So, there are actually 3 issues:
Tested on Windows, Linux and FreeBSD. I don't have an Apple machine, so can't test there. Don't have a joystick either, so someone else will have to test the Unix accelerometer/joystick detection code. If anyone has anything else to add to the commit, feel free to do so or mention it in a line comment.
Thanks a lot for the fix, it looks like all my problems have gone: no memory leaks and no those messages. I like the refactoring as well with a tiny addition that you can see in the code.
The only thing is warnings when I compile:
SFML/Window/Unix/JoystickImpl.cpp: In static member function ‘static bool sf::priv::JoystickImpl::isConnected(unsigned int)’:
P.S.: Nowadays it doesn't happen often when Valgrind logs are entirely clean - I am impressed with quality of SFML. Well done, guys!
P.P.S.: I only tested on Linux (Mint, 64 bit) - same machine that used before.