REVIEWED: LoadDroppedFiles()
, fixed issues
This commit is contained in:
parent
a6e31cadbd
commit
d4f60f8303
1 changed files with 26 additions and 18 deletions
44
src/rcore.c
44
src/rcore.c
|
@ -3221,21 +3221,8 @@ FilePathList LoadDroppedFiles(void)
|
||||||
{
|
{
|
||||||
FilePathList files = { 0 };
|
FilePathList files = { 0 };
|
||||||
|
|
||||||
if (CORE.Window.dropFileCount > 0)
|
files.count = CORE.Window.dropFileCount;
|
||||||
{
|
files.paths = CORE.Window.dropFilepaths;
|
||||||
files.count = CORE.Window.dropFileCount;
|
|
||||||
files.paths = (char **)RL_CALLOC(files.count, sizeof(char *));
|
|
||||||
|
|
||||||
for (int i = 0; i < files.count; i++)
|
|
||||||
{
|
|
||||||
files.paths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
|
||||||
strcpy(files.paths[i], CORE.Window.dropFilepaths[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// WARNING: We reset drop file count after loading the stored paths,
|
|
||||||
// despite internally GLFW probably keeps the pointers until next drop
|
|
||||||
CORE.Window.dropFileCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
@ -3243,11 +3230,16 @@ FilePathList LoadDroppedFiles(void)
|
||||||
// Unload dropped filepaths
|
// Unload dropped filepaths
|
||||||
void UnloadDroppedFiles(FilePathList files)
|
void UnloadDroppedFiles(FilePathList files)
|
||||||
{
|
{
|
||||||
|
// WARNING: files pointers are the same as internal ones
|
||||||
|
|
||||||
if (files.count > 0)
|
if (files.count > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < files.count; i++) RL_FREE(files.paths[i]);
|
for (int i = 0; i < files.count; i++) RL_FREE(files.paths[i]);
|
||||||
|
|
||||||
RL_FREE(files.paths);
|
RL_FREE(files.paths);
|
||||||
|
|
||||||
|
CORE.Window.dropFileCount = 0;
|
||||||
|
CORE.Window.dropFilepaths = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5583,12 +5575,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
|
||||||
// NOTE: Paths are stored in dynamic memory for further retrieval
|
|
||||||
// Everytime new files are dropped, old ones are discarded
|
|
||||||
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
|
static void WindowDropCallback(GLFWwindow *window, int count, const char **paths)
|
||||||
{
|
{
|
||||||
CORE.Window.dropFilepaths = paths;
|
// In case previous dropped filepaths have not been freed, we free them
|
||||||
|
if (CORE.Window.dropFileCount > 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilepaths[i]);
|
||||||
|
|
||||||
|
RL_FREE(CORE.Window.dropFilepaths);
|
||||||
|
|
||||||
|
CORE.Window.dropFileCount = 0;
|
||||||
|
CORE.Window.dropFilepaths = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 *));
|
||||||
|
|
||||||
|
for (int i = 0; i < CORE.Window.dropFileCount; i++)
|
||||||
|
{
|
||||||
|
CORE.Window.dropFilepaths[i] = (char *)RL_CALLOC(MAX_FILEPATH_LENGTH, sizeof(char));
|
||||||
|
strcpy(CORE.Window.dropFilepaths[i], paths[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue