Skip to content

Commit

Permalink
Merge pull request #2 from DreamRealityInteractive/feature/shutdown_f…
Browse files Browse the repository at this point in the history
…rom_script

Shutdown imgui from a script final() function
  • Loading branch information
dri-richard authored Nov 10, 2023
2 parents b564cfc + c6c87c6 commit 1695463
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions netimgui/api/netimgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
- name: disconnect
type: function

#*****************************************************************************************************

- name: shutdown
type: function

#*****************************************************************************************************

- name: is_connected
Expand Down
2 changes: 2 additions & 0 deletions netimgui/netimgui.script
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function init(self)
end

function final(self)
netimgui.shutdown()

if self.acquire_input_focus then
msg.post(".", "release_input_focus")
end
Expand Down
14 changes: 11 additions & 3 deletions netimgui/src/extension_netimgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ static int netimgui_ConnectToApp(lua_State *L)
static int netimgui_ConnectFromApp(lua_State *L)
{
DM_LUA_STACK_CHECK(L, 0);
//imgui_NewFrame();
const char* client_name = luaL_checkstring(L, 1);
NetImgui::ConnectFromApp(client_name);
return 0;
Expand All @@ -33,11 +32,17 @@ static int netimgui_ConnectFromApp(lua_State *L)
static int netimgui_Disconnect(lua_State *L)
{
DM_LUA_STACK_CHECK(L, 0);
//imgui_NewFrame();
NetImgui::Disconnect();
return 0;
}

static int netimgui_Shutdown(lua_State *L)
{
DM_LUA_STACK_CHECK(L, 0);
NetImgui::Shutdown();
return 0;
}

static int netimgui_IsConnected(lua_State *L)
{
DM_LUA_STACK_CHECK(L, 1);
Expand All @@ -55,6 +60,7 @@ static const luaL_reg Module_methods[] =
{"connect_to_app", netimgui_ConnectToApp},
{"disconnect", netimgui_Disconnect},
{"is_connected", netimgui_IsConnected},
{"shutdown", netimgui_Shutdown},
{0, 0}
};

Expand Down Expand Up @@ -91,7 +97,9 @@ dmExtension::Result AppFinalizeDefoldNetImGui(dmExtension::AppParams* params)
dmExtension::Result FinalizeDefoldNetImGui(dmExtension::Params* params)
{
dmLogInfo("FinalizeDefoldNetImGui");
NetImgui::Shutdown();
// Shutdown is now triggered from netimgui.script, to avoid a crash
// from a presumed race condition with imgui shutdown
//NetImgui::Shutdown();
return dmExtension::RESULT_OK;
}

Expand Down

0 comments on commit 1695463

Please # to comment.