Jump to content

Terminating and reinitializing LE


njord
 Share

Recommended Posts

Hello guys.

 

In my application, I want to activate and shut down LE engine multiple times based on user input. Anyone knows how to do it properly ? The below code crashes at 2nd "Graphics" function call.

 

Thanks in advance!

 

#include "engine.h"
#include <iostream>

void LEapp()
{
::Initialize(1);//engine debug mode
RegisterAbstractPath("D:/WORKSPACE/LESDK 2.40");
Graphics( 800, 600 ) ;

TFramework framework = CreateFramework();
TLayer layer = GetFrameworkLayer(0);
TCamera DefaultCam = GetLayerCamera(layer);
PositionEntity(DefaultCam,Vec3(0,0,0));

//Set Lua variable
BP L = GetLuaState();
lua_pushobject(L,framework);
lua_setglobal(L,"fw");
lua_pop(L,1);

SetStats(2);

while(!KeyHit(KEY_ESCAPE))
{
	// Update timing and world
	UpdateFramework();

	RenderFramework();

	Flip(0);
}

::Terminate();
}

int main( int argn, char* argv[] )
{
LEapp();
std::cout << "SECOND APP" << std::endl;
LEapp();
return 0;
}

Link to comment
Share on other sites

You can use a main.exe which uses WinExec() to launch a sub.exe which uses LE.

Even if you use Terminate(), the engine is not completely freed from memory, but it's only freed from memory when the exe is terminated.

On the other hand, why do you need to Terminate() the engine? It doesn't do anything if you don't use it's commands, so for example a simple Sleep(10000) would do the same as not running the engine at all, and sleeping 10 seconds.

Also when you do a FreeFramework() (or FreeWorld()) all memory the engine has allocated is freed, except for the commands itself.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Terminate() does unload the engine.dll from memory via FreeLibrary(hlib), but the Garbage Collection of BlitzMax (I am guessing that that is the reason), is preventing from releasing the freed dll from memory. Yeah, Garbage Collection is a synonym for bad memory management, since it causes only problems and no benefits at all.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

By the way, I needed this functionality because based on user input and selected simulation vehicle, i need to open a LE window and show things. If the user turns off the 3D window (deletes the particular vehicle), I never know if he will turn it on again. One workaround is to hide the LE window i guess. But I need to hack object oriented architecture of the simulator to do this, because my vehicles are dll plugins, and some of them create LE windows, others dont. I need to pass the windowhandle of vehicle plugin LE win to the simulator classes which is problematic.

Link to comment
Share on other sites

why not just restarting the game with the new setting applied?

I've done that before and i had no issues with it so far.

 

Edit:

Ok, never mind, i haven't read the posts properly :)

Edited by DaDonik

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Can't give any information on that, but maybe its because some internals must be closed before main goes out of scope.

Josh is the one who knows

 

If we are to depend on exe exit like Metatron said, then there is no sense in calling terminate function since Windows gets back the memory you borrowed automatically. Also even freeframewrok is unnecessary at some point, because we are already exiting the application when we call it dont we ?

 

By the way, project creator of Lesdk (2.40 the one I use now) does not even put a freeworld call at the end. It calls terminate directly.

 

I strongly agree with paramecij, there should be an ability to shut down and reinit the engine. Engines run and stop right ? Thats why they are called engines :)

Link to comment
Share on other sites

If we are to depend on exe exit like Metatron said, then there is no sense in calling terminate function since Windows gets back the memory you borrowed automatically. Also even freeframewrok is unnecessary at some point, because we are already exiting the application when we call it dont we ?

 

By the way, project creator of Lesdk (2.40 the one I use now) does not even put a freeworld call at the end. It calls terminate directly.

 

I strongly agree with paramecij, there should be an ability to shut down and reinit the engine. Engines run and stop right ? Thats why they are called engines :)

I'm not trying to argue for or against anything.

Josh is the creator and knows why.

Roland Strålberg
Website: https://rstralberg.com

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...