Crash When Increasing Capacity

Started by ForeverZer0, October 14, 2011, 09:17:48 pm

Previous topic - Next topic

ForeverZer0

I found a small problem with extending the maximum capacity for actors, classes, weapons, etc. in the editor.  Although it works, there is a limitation on how many objects can be added at one time using the "Change Maximum" method.

I found that when you try to increase the capacity by much more than 1,000 at a time, the application will crash. I capped the maximum size at 9999, but it is not possible to simple go from say, 200 actors, to 2,000 or more without a crash. It works fine if you add 1,000, which will simply cause an expected second or two of lag while the Actor objects are being created and the list is being populated.

I don't if this information is pertinent or not, but 1,000 actor objects translates into roughly 10 MB of RAM.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

I don't follow
are you saying that the lag caused by creating 1,000 new actors at once causes a crash? or that there simply being 1,000 actors causes a crash?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

No, can create as many as you want, just so long as it not much more than a 1,000 at a time.

I just committed, so update and see what I mean in the test solution.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

you need to not update the list box as you are adding the actors
make a method to refresh the list box and call it AFTER all the actors have been added
also it may be better to use list comprehension and make use of the extend method to add the actors to the list

if newMax != currentMax:
    if newMax > currentMax:
        newactors = [Actor() for i in range(newMax - currentMax)]
        Project.Data_actors.extend(newactors)

and then refresh the actors listbox
similarly for removing actors instead of looping and popping them out use the del statement and use a slice

if newMax != currentMax:
    if newMax > currentMax:
        #add actors
    else:
        del Project.Data_actors[newMax:CurrentMax]

now that particular slice may be offset from the slice you want by 1 index so you probably need to check that

all in all this should be faster and result in no crash.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

Alrighty, that seems better.
I'm still learning Python as I go, so please let me know if you notice any other things for me to improve on. There are still basic functions such as slice which I haven't even used yet :P
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

I take it after doing all that it didn't crash when adding more than 1000 actors/
I got it to crash before by adding 5000 actors at once will it still crash?
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

October 15, 2011, 01:13:23 am #6 Last Edit: October 15, 2011, 01:52:30 am by ForeverZer0
Actually, its still about the same.
I added 5000 actors, and so long as you don't try to click the window or anything, it won't crash, but it took 24 seconds, and my computer is not slow by any means.

I do have an idea. We can not initialize new actor instances while the list is being populated, but maybe use it more like a just-in-time function. If the selection is changed, check if anything exists in the corresponding container, and if not create it. This could cause issues when the data is supposed to be saved, but so long as we handle it properly, it should work.


EDIT:
I implemented it, and it can now fill the list with 9,999 items in less than a second. Data_actors is extended with a None, which can simply work as a placeholder for Actor, which can be initialized only when it needs to be, but it will keep track of the size of the container. So far, this looks to be the best way for performance. It may require a few more checks throughout the code to make sure items exist before accessing them, though.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Ryex

sounds good. we should do the same with everything initialize it with None and check to be sure it isn't none before we do anything with it
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Blizzard

Is this a problem that could prevent us from having 9999 actors or anything else for that matter? I'm also a bit concerned about the memory usage. 10 MB for 1000 actors would means that an actors needs 10 kB which is unrealistic.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Ryex

no it just prevents that many from being created at once you can still have 99999 actors. as for the memory usage, now that I think about it there is no way that one acotr instance freshly created is 10 KB, that's impossible. but if that's the case we should probably look into a deferred loading option and try to only hold the data in memory that is actively being worked on. storing the rest in a temp folder.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

ForeverZer0

The RAM usage may not be the most accurate.
I just happen to have Task Manager open to the process tab, and noticed every time I added 1,000 actors, the "Memory (Private Working Set)" value would increase by 10 MB, give or take about 200 KB.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.