Tweak WindowDropCallback()
#2943
This commit is contained in:
parent
aae7ab64c7
commit
cf1ebada0e
1 changed files with 17 additions and 14 deletions
31
src/rcore.c
31
src/rcore.c
|
@ -5598,25 +5598,28 @@ static void CursorEnterCallback(GLFWwindow *window, int enter)
|
||||||
// GLFW3 Window Drop Callback, runs when drop files into window
|
// GLFW3 Window Drop Callback, runs when drop files into window
|
||||||
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
|
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
|
||||||
{
|
{
|
||||||
// In case previous dropped filepaths have not been freed, we free them
|
if (count > 0)
|
||||||
if (CORE.Window.dropFileCount > 0)
|
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]);
|
// In case previous dropped filepaths have not been freed, we free them
|
||||||
|
if (CORE.Window.dropFileCount > 0)
|
||||||
|
{
|
||||||
|
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]);
|
||||||
|
|
||||||
RL_FREE(CORE.Window.dropFilepaths);
|
RL_FREE(CORE.Window.dropFilepaths);
|
||||||
|
|
||||||
CORE.Window.dropFileCount = 0;
|
CORE.Window.dropFileCount = 0;
|
||||||
CORE.Window.dropFilepaths = NULL;
|
CORE.Window.dropFilepaths = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// WARNING: Paths are freed by GLFW when the callback returns, we must keep an internal copy
|
// WARNING: Paths are freed by GLFW when the callback returns, we must keep an internal copy
|
||||||
CORE.Window.dropFileCount = count;
|
CORE.Window.dropFileCount = count;
|
||||||
CORE.Window.dropFilepaths = (char **)RL_CALLOC(CORE.Window.dropFileCount, sizeof(char *));
|
CORE.Window.dropFilepaths = (char **)RL_CALLOC(CORE.Window.dropFileCount, sizeof(char *));
|
||||||
|
|
||||||
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++)
|
for (unsigned int i = 0; i < CORE.Window.dropFileCount; i++)
|
||||||
{
|
{
|
||||||
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||||
strcpy(CORE.Window.dropFilepaths[i], paths[i]);
|
strcpy(CORE.Window.dropFilepaths[i], paths[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue