Crash on exit if world not deleted

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Crash on exit if world not deleted

Postby pHySiQuE » Sat Jun 09, 2012 4:00 pm

If I call NewtonCreate() and then exit(0) in debug mode, in Visual Studio 2008, an error pops up. Can this behavior be changed? I don't want the user to have to delete every world when exiting the program.
Code: Select all
   NewtonCreate();
   exit(0);

Capture.JPG
Capture.JPG (29.4 KiB) Viewed 1184 times

Capture2.JPG
Capture2.JPG (135.83 KiB) Viewed 1184 times
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Crash on exit if world not deleted

Postby Julio Jerez » Sat Jun 09, 2012 4:16 pm

that is the equivalent of doing this

Code: Select all
malloc (100);
exit(0);


you will leave a memory leak behind

if you want to do that you will need to install an
int atexit( void (__cdecl *func )( void ));

function callback that let you call destroy. eieth that oy you cna comment out the assert, in dgGlobalAllocator()
I would not recomned that since you will them not knwo if you have leacks.

the proper way to handle this , I believe, is by installing and atexit() callback.

better yet is not to use exit() at all.
exit is a very all faction and draconian programming style, that date from, the unstructure days of C.
clean code should not use exit() and at exit() under any circuntances.


also what do you mean "I don't want the user to have to delete every world when exiting the program."
if you exit a program all memory should be reclaimed.
if the application does not do graciuoslly, the OS will do it for you nastilly. Basically your app will stay there for a long time while the OS is tracking all dangling memory allocations.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Crash on exit if world not deleted

Postby pHySiQuE » Sat Jun 09, 2012 4:26 pm

I think it's the operating system's job to free memory on exit, but I can just comment this out.
pHySiQuE
 
Posts: 608
Joined: Fri Sep 02, 2011 9:54 pm

Re: Crash on exit if world not deleted

Postby Julio Jerez » Sat Jun 09, 2012 4:34 pm

not the OS does it for different reasons. By it is not its job, it is that app job the OS does as a hostile memory take over.
has you even seen programe that take for ever when you exits? that is teh OS scanning teh virtual memory pager for dangling memory leaks.

bu in any case, the check there is not only to make sure the memory is zero on exit, it also check that the memory used by a newton world i zero when you destroy that world.
you can destroy a world without exiting the program, the test demo does many many time and once in a while adding something new sometime I make a leak.
it is that function that keeps the code sane.

like I say you can commnet put the assert.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron