yglukhov / jnim

Nim - Java bridge
MIT License
184 stars 13 forks source link

jexport: objects constructed by Java have .data == nil #60

Closed akavel closed 4 years ago

akavel commented 4 years ago

The following lines generated by implementConstructor:

https://github.com/yglukhov/jnim/blob/de5f19900c88200ce3eef94abbb4332ea7bd13ce/jnim/private/jni_export.nim#L288-L290

are only executed if the Nim constructor (proc new) is called to create/construct a Jnim object. But when the object is created from Java code (the Java-exported constructor of the class is called), the setNimDataToJObject procedure is never executed, and thus this.data is nil in such an object.

To fix this, I think the code initializing the .data field could be moved to the Java constructor (e.g. as a native private helper function to be called from the constructor, similar to the _0 and _1 method & field).

I will try to workaround this temporarily in my current code; I hope to get back to fixing this properly later in the future. For now I'm opening the issue for the record.

akavel commented 4 years ago

Fixed in d3a83367df25bf297c8d788f9e6b6d7b55ac29b4.