njord Posted August 10, 2011 Share Posted August 10, 2011 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; } Quote Link to comment Share on other sites More sharing options...
njord Posted August 15, 2011 Author Share Posted August 15, 2011 up Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 15, 2011 Share Posted August 15, 2011 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
paramecij Posted August 15, 2011 Share Posted August 15, 2011 ..so why do we have the Terminate() function again? .. I think every serious or pro library should have a clean exit method and the ability to initialize it again .. else it hints of bad memory management etc.. Quote Link to comment Share on other sites More sharing options...
Canardia Posted August 15, 2011 Share Posted August 15, 2011 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Roland Posted August 16, 2011 Share Posted August 16, 2011 Yeah, Garbage Collection is a synonym for bad memory management, since it causes only problems and no benefits at all. I tend to agree with you here Metadron Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
njord Posted August 16, 2011 Author Share Posted August 16, 2011 I am confused. On the other hand, why do you need to Terminate() the engine? If no one will ever need to terminate the engine, why is there a terminate function in LE ? Quote Link to comment Share on other sites More sharing options...
njord Posted August 16, 2011 Author Share Posted August 16, 2011 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. Quote Link to comment Share on other sites More sharing options...
Roland Posted August 16, 2011 Share Posted August 16, 2011 I am confused. If no one will ever need to terminate the engine, why is there a terminate function in LE ? 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 Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
DaDonik Posted August 16, 2011 Share Posted August 16, 2011 (edited) 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 August 16, 2011 by DaDonik Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
njord Posted August 16, 2011 Author Share Posted August 16, 2011 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 Quote Link to comment Share on other sites More sharing options...
Roland Posted August 16, 2011 Share Posted August 16, 2011 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. Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
njord Posted August 16, 2011 Author Share Posted August 16, 2011 I'm not trying to argue for or against anything. Josh is the creator and knows why. Sorry if I sounded aggressive. I didnt mean that Quote Link to comment Share on other sites More sharing options...
Roland Posted August 16, 2011 Share Posted August 16, 2011 Sorry if I sounded aggressive. I didnt mean that No problem Quote Roland Strålberg Website: https://rstralberg.com Link to comment Share on other sites More sharing options...
Recommended Posts
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.