mlx_mouse_hide causes memory leaks
Opened this issue · 2 comments
aenglert42 commented
It seems that mlx_mouse_hide allocates memory but has no function to free it.
CarloCattano commented
Agree
ejacquem commented
you can fix the leak with the library Xfixes
- include the library (<X11/extensions/Xfixes.h>) in the mlx_mouse.c
- add the functions
XFixesHideCursor(xvar->display, win->window);
andXFixesShowCursor(xvar->display, win->window);
in the corresponding minilibx functions. - compile your project with the flag -lXfixes
Be advised the cursor will disappear even outside the program until it is closed.
the mlx_mouse.c should look like this :
#include "mlx_int.h"
#include <X11/extensions/Xfixes.h>
int mlx_mouse_move(t_xvar *xvar, t_win_list *win, int x, int y)
{
XWarpPointer(xvar->display, None, win->window, 0, 0, 0, 0, x, y);
return (0);
}
int mlx_mouse_hide(t_xvar *xvar, t_win_list *win)
{
XFixesHideCursor(xvar->display, win->window);
}
int mlx_mouse_show(t_xvar *xvar, t_win_list *win)
{
XFixesShowCursor(xvar->display, win->window);
}
....