Skip to content

Commit

Permalink
LuaFAR plugins: the timer queue is closed in DllMain/DLL_PROCESS_DETACH
Browse files Browse the repository at this point in the history
Was: in ExitFARW
  • Loading branch information
shmuz committed Jan 22, 2025
1 parent 4494671 commit 4d9cf65
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion plugins/luamacro/_globalinfo.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function export.GetGlobalInfo()
return {
Version = { 3, 0, 0, 862 },
Version = { 3, 0, 0, 863 },
MinFarVersion = { 3, 0, 0, 6380 },
Guid = win.Uuid("4EBBEFC8-2084-4B7F-94C0-692CE136894D"),
Title = "LuaMacro",
Expand Down
6 changes: 6 additions & 0 deletions plugins/luamacro/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
shmuel 2025-01-22 20:36:47+02:00 - build 863

1. LuaFAR plugins: the timer queue is closed in DllMain/DLL_PROCESS_DETACH.
Was: in ExitFARW.


shmuel 2025-01-21 21:18:49+02:00 - build 862

1. Force garbage collection on reloading macrofiles
Expand Down
18 changes: 10 additions & 8 deletions plugins/luamacro/luafar/exported.c
Original file line number Diff line number Diff line change
Expand Up @@ -1251,22 +1251,24 @@ intptr_t LF_SetFindList(lua_State* L, const struct SetFindListInfo *Info)
return ret;
}

void LF_ExitFAR(lua_State* L, const struct ExitInfo *Info)
void LF_DoFinalCleanup(lua_State* L)
{
HANDLE hQueue;
(void)Info;

if (GetExportFunction(L, "ExitFAR")) //+1: Func
pcall_msg(L, 0, 0); //+0

hQueue = GetLuaStateTimerQueue(L); //+0
HANDLE hQueue = GetLuaStateTimerQueue(L);
if (hQueue)
{
DeleteLuaStateTimerQueue(L);
DeleteTimerQueueEx(hQueue, NULL);
}
}

void LF_ExitFAR(lua_State* L, const struct ExitInfo *Info)
{
(void)Info;

if (GetExportFunction(L, "ExitFAR")) //+1: Func
pcall_msg(L, 0, 0); //+0
}

void getPluginMenuItems(lua_State* L, struct PluginMenuItem *pmi, const char* namestrings,
const char* nameguids, int cpos)
{
Expand Down
1 change: 1 addition & 0 deletions plugins/luamacro/luafar/luafar.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ DLLFUNC intptr_t LF_SetFindList(lua_State* L, const struct SetFindListInfo *Info
DLLFUNC intptr_t LF_GetContentFields(lua_State* L, const struct GetContentFieldsInfo *Info);
DLLFUNC intptr_t LF_GetContentData(lua_State* L, struct GetContentDataInfo *Info);
DLLFUNC void LF_FreeContentData(lua_State* L, const struct GetContentDataInfo *Info);
DLLFUNC void LF_DoFinalCleanup(lua_State* L);

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion plugins/luamacro/luafar/luaplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)

if (DLL_PROCESS_ATTACH == dwReason && hDll)
InitGlobal(&G, (HINSTANCE)hDll);
else if (DLL_PROCESS_DETACH == dwReason)
else if (DLL_PROCESS_DETACH == dwReason) {
LF_DoFinalCleanup(G.LS);
DestroyGlobal(&G);
}

return TRUE;
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/luamacro/luafar/version.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#include <farversion.hpp>

#define PLUGIN_BUILD 862
#define PLUGIN_BUILD 863

1 comment on commit 4d9cf65

@shmuz
Copy link
Contributor Author

@shmuz shmuz commented on 4d9cf65 Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case:

  1. A macrofile containing a Console Input event handler (see below)
  2. Run Far, move panel cursor a little
  3. Close Far by clicking on [x] in the upper-right corner
  4. In 30-50% of cases Far crashes
Event {
  group="ConsoleInput";
  description="Crash test";
  action=function()
    far.Timer(10, function(h) h:Close() end)
  end;
}

Please sign in to comment.