CGTalk > Software Specific Forums > Autodesk 3ds max > 3dsMax SDK and MaxScript
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 04-11-2012, 08:22 PM   #1
DustinBrown
Lord of the posts
 
DustinBrown's Avatar
portfolio
Dustin Brown
Character Artist
San Diego, USA
 
Join Date: Oct 2003
Posts: 560
Garbage Collection Error

I'm running into a garbage collection issue. I suspect the cause is a function I made which loops through meshes in my scene and automatically creates materials and fetches the proper texture maps. It's a pretty involved process - switching between SME and Compact ME to perform various operations, loading TGA files, etc.

I don't know how to find out, for certain, if this is the function that's causing the garbage collection error, but my gut tells me it is. The error occurs when I load the next scene to run the script on. I have over a hundred scene files I need to run the script on. I'm currently having to shut Max down between scene files, which sucks.



I've tried adding gc() at the end of the function I believe to be the culprit, but that doesn't seem to have helped, I still the get error when I open the next scene file.

At this point I'm looking for suggestions of more surgical methods to avoid these sorts of errors. I've read the help doc's pages on memory management and garbage collection, which is good information. Also, this thread seems helpful:

http://forums.cgsociety.org/showthr...ghlight=garbage

Bobo's comment about "Possible causes: getting a mesh value inline or again and again without deleting it manually after the use, incremental string and array appending operations, bitmap value definitions inside the loop etc." has me interested in learning how to perform some of these manual operations to manage the memory profile for the script.
__________________
Portfolio

Last edited by DustinBrown : 04-11-2012 at 08:26 PM.
 
Old 04-11-2012, 09:27 PM   #2
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,102
Send a message via ICQ to denisT
first of all:
#1 how much initial heap allocation memory for max scripts do you have?
#2 do you open bitmaps during the script run?
#3 do you free opened bitmaps before loading new file?
#4 do you reset max file before loading the new one?
 
Old 04-11-2012, 09:46 PM   #3
DustinBrown
Lord of the posts
 
DustinBrown's Avatar
portfolio
Dustin Brown
Character Artist
San Diego, USA
 
Join Date: Oct 2003
Posts: 560
Thanks for the reply.

#1 how much initial heap allocation memory for max scripts do you have?

print heapSize
23373864L

#2 do you open bitmaps during the script run?

I'm not sure if bitmaps are being "opened" or not. To fetch the bitmap I'm using:
Code:
skinDiff = bitmapTexture filename:(maxFilePath+nnn+"color.tga")


Is that considered "opening" a bitmap? I don't see a bitmap selection dialog open when the script runs. I think it's just using the path and filename info I give it to go directly to the file.

#3 do you free opened bitmaps before loading new file?

Again, I'm not sure what is considered "opening" a bitmap, but no I'm not doing anything specifically to free bitmaps. According to the docs, gc does this among other things.

#4 do you reset max file before loading the new one?

I have tried this and I still get the garbage collection error.
__________________
Portfolio
 
Old 04-11-2012, 10:06 PM   #4
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,102
Send a message via ICQ to denisT
Quote:
Originally Posted by DustinBrown
#1 how much initial heap allocation memory for max scripts do you have?

print heapSize
23373864L

#2 do you open bitmaps during the script run?

I'm not sure if bitmaps are being "opened" or not. To fetch the bitmap I'm using:
Code:
skinDiff = bitmapTexture filename:(maxFilePath+nnn+"color.tga")


Is that considered "opening" a bitmap? I don't see a bitmap selection dialog open when the script runs. I think it's just using the path and filename info I give it to go directly to the file.

#3 do you free opened bitmaps before loading new file?

Again, I'm not sure what is considered "opening" a bitmap, but no I'm not doing anything specifically to free bitmaps. According to the docs, gc does this among other things.

#4 do you reset max file before loading the new one?

I have tried this and I still get the garbage collection error.


#1 you have to add initial memory to be allocated. Go to the preference settings and set maxscript initial heap allocation to ~128 Mbytes
#2 you are opening bitmaps. so...
#3 free old bitmaps before loading new file. use freeSceneBitmaps() for that.
#4 try to do resetMaxFile() and DON'T do any gc()

Last edited by denisT : 04-12-2012 at 06:56 PM.
 
Old 04-12-2012, 06:53 PM   #5
DustinBrown
Lord of the posts
 
DustinBrown's Avatar
portfolio
Dustin Brown
Character Artist
San Diego, USA
 
Join Date: Oct 2003
Posts: 560
I'll give that a shot, thank you!
__________________
Portfolio
 
Old 04-14-2012, 08:23 AM   #6
jedie
Expert
portfolio
jens d.
jojo, Germany
 
Join Date: Oct 2009
Posts: 336
Quote:
Originally Posted by DustinBrown
I'm running into a garbage collection issue.



I had the same error some time ago... I haven't any bitmap stuff in the scene. It allways happens if i use "reset max". It was depending on which scene was open.

Solution: startup a fresh max, merge all objects from the problematic scene.

Quote:
Originally Posted by denisT
DON'T do any gc()

Is this a general tip? I use it on almost all scripts at the end...
 
Old 04-14-2012, 11:42 AM   #7
denisT
MAX Doctor
 
denisT's Avatar
portfolio
Denis Trofimov
CA, USA
 
Join Date: Jul 2009
Posts: 9,102
Send a message via ICQ to denisT
Quote:
Originally Posted by jedie
Is this a general tip? I use it on almost all scripts at the end...

reset the max scene does do garbage collection. we are looking for the most stable solution for the batch process. i just don't want to do gc two times in this case.
 
Old 05-18-2012, 10:22 PM   #8
DustinBrown
Lord of the posts
 
DustinBrown's Avatar
portfolio
Dustin Brown
Character Artist
San Diego, USA
 
Join Date: Oct 2003
Posts: 560
Apologies for the necro thread, but I'm still having GC problems and I believe I've narrowed the problem down to SME.

Similar threads I've found:
http://forums.cgsociety.org/showthread.php?t=929019
http://forums.cgsociety.org/showthr...p?f=98&t=357942

This is the code I have:
Code:
fn stripMats = ( -- Remove material assignments on all objects in the scene for obj in objects do ( obj.material = null ) -- COMPACT MATERIAL EDITOR matEditor.mode = #basic -- Sets ME to compact mode actionMan.executeAction 0 "50048" -- Tools: Material Editor actionMan.executeAction 2 "40293" -- Material Editor: Cycle 3X2, 5X3, 6X4 Sample Slots actionMan.executeAction 2 "40293" -- Material Editor: Cycle 3X2, 5X3, 6X4 Sample Slots matEditor.Close() macros.run "Medit Tools" "clear_medit_slots" --freeSceneBitmaps() -- Clears all scene bitmaps out of memory --saveMaxFile (maxFilePath+maxFileName) -- SLATE MATERIAL EDITOR (SME) matEditor.mode = #advanced sme.deleteView 1 false -- Delete current slate in SME newView = sme.getView(sme.createView "Character Materials") -- Make a new slate in SME --actionMan.executeAction 0 "40130" -- Redraw all views --max select none --freeSceneBitmaps() -- Clears all scene bitmaps out of memory --saveMaxFile (maxFilePath+maxFileName) )


I've tried running each half of the function alacarte and I'm almost certain it's the SME stuff that's causing GC problem. I have set my initial heap allocation to 128MB under Preferences, but that hasn't helped at all. You can also see that I've been commenting out (essentially removing) things as a process of elimination to try to narrow the problem down. Even with the above things commented out I still get GC errors any time I reset the scene or try to open a new scene.

My workstation has 12GB of RAM, so memory shouldn't be an issue.
__________________
Portfolio
 
Old 05-18-2012, 10:22 PM   #9
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,481
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 05:42 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.