lambdaisland / cljbox2d

Mozilla Public License 2.0
40 stars 3 forks source link

Odd issues when following a processing tutorial #5

Closed Folcon closed 1 year ago

Folcon commented 1 year ago

So I've been using this lib and following on with a series of tutorials by coding train and I'm seeing some odd behaviour + some minor issues. I thought it might be worthwhile documenting them here for the moment.

If they're in scope as things to fix to improve the library and need new issues focused on them to be opened for traceability / reproduction steps, happy to help and write up.

  1. Access Error, perhaps related to newer JVM versions:
        lambdaisland.cljbox2d/add-body                          cljbox2d.cljc                           :606
        clojure.core/run!                                       core.clj                                :7778
        clojure.core/reduce                                     core.clj                                :6885
        clojure.lang.PersistentVector::reduce                   PersistentVector.java                   :343
        clojure.core/run!/fn--8880                              core.clj                                :7783
        clojure.core/partial/fn--5908                           core.clj                                :2641
        lambdaisland.cljbox2d/add-fixture                       cljbox2d.cljc                           :593
        lambdaisland.cljbox2d/fixture-def                       cljbox2d.cljc                           :344
        clojure.lang.MultiFn::invoke                            MultiFn.java                            :229
        lambdaisland.cljbox2d/eval8293/fn--8295                 cljbox2d.cljc                           :265
    IllegalAccessError: Update to non-static final field org.jbox2d.collision.shapes.CircleShape.m_p attempted from a different class (lambdaisland.cljbox2d$eval8293$fn__8295) than the field's declaring class

This occurred when I tried creating:

(b/add-body
  world
  {:position pos
   :type :dynamic
   :fixtures [{:shape [:circle [20 20] 20]}]})
  1. Access Error, on distance joint:
        lambdaisland.cljbox2d/add-joint                         cljbox2d.cljc                           :618
        lambdaisland.cljbox2d/joint-def                         cljbox2d.cljc                           :420
    IllegalAccessError: Update to non-static final field org.jbox2d.dynamics.joints.DistanceJointDef.localAnchorA attempted from a different class (lambdaisland.cljbox2d$joint_def) than the field's declaring class

This occurred when I tried creating:

(b/add-joint
  world
  {:type :distance
   :bodies [(keyword (str next-id)) (keyword (str (inc next-id)))]
   :local-anchors [[0 0] [0 0]]
   :frequency 3
   :damping 0.1
   :length 32}]})

I'm trying to figure out a workaround for these and there is some information available however, getting the correct module name for org.jbox2d.dynamics.joints.DistanceJointDef is like pulling teeth... "", does not appear to be acceptable with many variants of:

WARNING: Unknown module: org.jbox2d.dynamics specified to --add-opens

Trying to filter the module layer does not seem to work either:

(-> (java.lang.ModuleLayer/boot)
  (.modules)
  (.stream)
  (.filter (proxy [java.util.function.Predicate] []
             (test [i] (.contains (.getPackages i) "org.jbox2d"))))
  (.findAny))
=> #object[java.util.Optional 0x78e02422 "Optional.empty"]

I'll add more here as I find issues.

plexus commented 1 year ago

It may be a code path that I never really tested. Would you be able to share a sample repo? it would help me a lot to be able to just run some code and see what's going on. Thanks!

plexus commented 1 year ago

Didn't you also have an issue with rotation here?

plexus commented 1 year ago

Are you using our fork of jbox2d?

  lambdaisland/jbox2d-library      {:mvn/version "2.3.1.756"}
Folcon commented 1 year ago

Didn't you also have an issue with rotation here?

This turned out to be more me not using the :density, :friction, :restitution numbers correctly, so I removed that part from the issue, my bad 😊...

Are you using our fork of jbox2d?

  lambdaisland/jbox2d-library      {:mvn/version "2.3.1.756"}

As far as I can tell I am using that? At least lein deps :tree says so =)...

It may be a code path that I never really tested. Would you be able to share a sample repo? it would help me a lot to be able to just run some code and see what's going on. Thanks!

I've created a branch here, I've reproed the issue running on corretto-19, but from my reading this is related to changes in access to reflection/isolation changes and likely will be an issue with any "newer" JDK.

plexus commented 1 year ago

Ok as I suspected this was simply an untested code path, I hadn't used the 2-arity version of the circle constructor. Apparently the m_p vector is final, so you have to mutate the vector itself, rather than re-assigning it.

I cut a release from main, which also contains some other changes that hadn't been released yet.

[com.lambdaisland/cljbox2d "0.7.43"]
{com.lambdaisland/cljbox2d {:mvn/version "0.7.43"}}

I ran through all the demos, and your repro, and they run find on Java 11 (which is post-jigsaw, so any issues with the module system should already be apparent.)

The error message you got about modules being inaccessible was a red herring, the real issue is we're trying to mutate a final field.

public class CircleShape extends Shape {

  public final Vec2 m_p;
  ...
}

Please give this a whirl and let me know how it goes. If you make something halfway cool then you are very much encouraged to submit it to the demos.

Thanks for trying cljbox2d.