Author Topic: jPCT-AE calcNormals() mutli threading exception  (Read 2547 times)

Offline jd

  • byte
  • *
  • Posts: 2
    • View Profile
jPCT-AE calcNormals() mutli threading exception
« on: December 22, 2015, 10:34:10 pm »
Hi,
I'm creating a complex GUI with jpct and need to use multi threading in many parts.

When multiple threads then try to calculate the normals of objects at the same time I get an exception like:
java.lang.ArrayIndexOutOfBoundsException: index=40 length=29
at com.threed.jpct.Mesh.calcNormalsFast(Mesh.java:988)
at com.threed.jpct.Mesh.calcNormals(Mesh.java:543)
at com.threed.jpct.Object3D.calcNormals(Object3D.java:3336)


It would really great if you could modify it to allow multi threading!

Thanks!

J. D.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jPCT-AE calcNormals() mutli threading exception
« Reply #1 on: December 23, 2015, 12:25:51 am »
jPCT-AE isn't thread safe, so you are actually not supposed to do this. However, in this particular case, I guess I can make it thread safe without causing too much trouble or overhead. But why are you doing this in this first place? If normal calculations are an issue, it's usually better to use serialized objects (http://www.jpct.net/wiki/index.php?title=Differences_between_jPCT_and_jPCT-AE#Performance_and_memory_issues.2C_serialized_objects) if applicable.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jPCT-AE calcNormals() mutli threading exception
« Reply #2 on: December 23, 2015, 12:30:54 am »
BTW: I've moved this thread. It's neither a bug nor does it belong in the desktop jPCT section... ;)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: jPCT-AE calcNormals() mutli threading exception
« Reply #3 on: December 23, 2015, 12:35:33 am »
Try this jar and see if it helps: http://jpct.de/download/beta/jpct_ae.jar

Offline jd

  • byte
  • *
  • Posts: 2
    • View Profile
Re: jPCT-AE calcNormals() mutli threading exception
« Reply #4 on: December 23, 2015, 08:23:30 am »
Thank you very much. I didn't know it's not made to be thread safe, good to know for future use to look out for it. And especially the tip about serializing is great!