java - ArrayList size() method crashing program -
i developing game using lwjgl 3.0.0b , strange occurrence has come up.
background:
i have custom entity class , entity manager store entities in. when entity updated method gets called named "ticktrail
" adds in trail entity make graphics visually better , entertaining.
already have simplified down entities.size()
function, yes try solve myself :p
a solution have replacing methods similar this:
for (int = 0; < entities.size(); i++) { //calls method drawing, updating, or input }
to replace every single entities.size()
size
. size
being variable changed upon when entity added, removed, list cleared, or enemies removed.
this method work 100%, window dragging not crash program using method.
question
so sum up, final question why occur? haven't determined why dragging window , using arraylist's size() method crashes program, yet storing variable in place fine.
any or explanation strange phenomenon highly appreciated :)
edit last edit proved incorrect, size variable in use program still crashes, time go drawing board....
edit two okay, window dragging works other times doesn't, might more simple size() method call :/
based on little you've provided, i'm guessing multiple threads accessing arraylist concurrently , threads stomping on other.
if you're not creating list via collections.synchronizedlist() guarantee operations on list atomic internals of array aren't corrupted.
the reason went down path dragging windows generating multiple events update array, , you're trying iterate through @ same time.
when use variable watch size, concurrency issues go away. of course, don't have correct values in variable unless using atomicinteger or whatever, @ least exceptions aren't being thrown.
Comments
Post a Comment