www.jpct.net
jPCT - a 3d engine for Java => Support => Topic started by: eye1 on September 26, 2006, 01:08:22 am
-
Hello
I store few SimpleVectors in collection class Hashtable like that
protected Hashtable places = new Hashtable();
public void updateKoordinates()
{
SimpleVector place = part.getOrigin();
place.add(new SimpleVector(-50, -55, 80));
places.put("0001", place);
place = part.getOrigin();
place.add(new SimpleVector(-50, -55, -420));
places.put("0002", place);
place = part.getOrigin();
place.add(new SimpleVector( 50, -55, -420));
places.put("0003", place);
place = part.getOrigin();
place.add(new SimpleVector( 50, -55, 80));
places.put("0004", place);
}
public SimpleVector placePos(String placeNr)
{
System.out.println(places.get(placeNr));
return (SimpleVector)places.get(placeNr);
}
The method updateKoordinates() is called only once.
After some time of runing my application and calling method placePos(placeNr)... SimpleVector cordinates are changed. Anyone has idea what could cause that??
Thanks
-
Anyone has idea what could cause that??
Yes...you! :wink: You are modifying the SimpleVectors somewhere, may it be an implicit or explicit modification. Replace
return (SimpleVector)places.get(placeNr);
with
return new SimpleVector((SimpleVector)places.get(placeNr));
and the SimpleVectors in the map should remain unchanged.
-
Thank you Egon!
What a silly mistake :oops: :oops:
And i was reducing nr. of threads in my application, using only synchronized collections, synchronizing iterators and in the end it was so simple. :oops: :oops: . And i found the place where i was changing SimpleVector.
Thanks again!!
-
No problem. I'm always glad if i can help. Remember that everything that i can comment on is something that i did wrong myself in the past... :wink: