#jogamp @ irc.freenode.net - 20160831 05:05:10 (UTC)
20160831 05:05:10 -jogamp- Previous @ http://jogamp.org/log/irc/jogamp_20160830050510.html
20160831 05:05:10 -jogamp- This channel is logged @ http://jogamp.org/log/irc/jogamp_20160831050510.html
20160831 05:08:58 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 05:13:53 * juank_prada (~juank_pra@anon) Quit (Ping timeout: 265 seconds)
20160831 06:10:33 * elect (~elect@anon) has joined #jogamp
20160831 06:42:56 * jvanek (jvanek@anon) has joined #jogamp
20160831 06:59:45 <elect> hi
20160831 07:08:06 * monsieur_max (~maxime@anon) has joined #jogamp
20160831 07:35:27 <elect> any jna skillz here?
20160831 07:35:46 <zubzub> <-
20160831 07:36:02 <zubzub> sort of
20160831 07:36:07 <elect> good
20160831 07:36:15 <elect> Im newbie
20160831 07:36:23 <elect> I guess what I need is really the basic
20160831 07:36:37 <zubzub> jna is quite cumbersome in some aspects
20160831 07:36:52 <zubzub> ie very non intuitive for certain very common C cases
20160831 07:37:31 <zubzub> http://www.eshayne.com/jnaex/index.html?example=1
20160831 07:37:33 <zubzub> is very handy
20160831 07:37:45 <zubzub> http://www.eshayne.com/jnaex/index.html
20160831 07:38:46 <elect> here i am trying to read a model
20160831 07:38:46 <elect> https://github.com/jovr/jogl-hello-vr/blob/master/jogl-hello-vr/src/helloVr/ModelsRender.java#L129-L145
20160831 07:39:39 <elect> this is the function I am calling https://github.com/jovr/jopenvr/blob/master/jopenvr/src/vr/IVRRenderModels_FnTable.java#L103-L106
20160831 07:39:54 <elect> the problem is the pointerByReference
20160831 07:40:53 <elect> this is the corresponding C++ code
20160831 07:40:53 <elect> https://github.com/ValveSoftware/openvr/blob/master/samples/hellovr_opengl/hellovr_opengl_main.cpp#L1685-L1692
20160831 07:41:12 <zubzub> ok
20160831 07:41:24 <elect> as you see I am trying to allocating a new pointerByReference
20160831 07:41:35 <elect> but how can I retrieve the loaded model after?
20160831 07:42:05 <elect> the calling seems correct, since it does takes some time to load the model
20160831 07:42:22 <elect> but then I have no idea how I can get the object later
20160831 07:42:36 <elect> I tried to RenderModel_t m = new RenderModel_t(modelReference_.getValue() / getPointer());
20160831 07:42:40 <elect> but it didnt work
20160831 07:43:06 <zubzub> why the "/ getPointer()"
20160831 07:43:29 <elect> I tried both
20160831 07:43:34 <zubzub> modelRef.getValue() returns a pointer
20160831 07:45:21 <zubzub> you know, things like that which are very common in jna but somehow hard to do, is exactly the reason I made my own jna like library
20160831 07:45:30 <zubzub> *very common in C/Cpp
20160831 07:45:52 <elect> uhm
20160831 07:46:29 <elect> the problem is that if I do
20160831 07:46:29 <elect> RenderModel_t m = new RenderModel_t(modelReference_.getValue());
20160831 07:46:37 <elect> m is still empty
20160831 07:48:46 <elect> any tips?
20160831 07:52:53 <zubzub> empty as in no values are set?
20160831 07:54:26 <zubzub> ah yes
20160831 07:54:32 <zubzub> did you call read on your struct?
20160831 07:56:44 <zubzub> iirc if you create struct from an pointer you have to call read() on it manually
20160831 07:56:59 <zubzub> so jna can copy the values from native to java
20160831 07:57:12 <zubzub> one of the (many) reasons jna is slow ;)
20160831 07:58:13 <zubzub> needless to say my lib doesn't do that :p
20160831 08:01:29 <zubzub> Pointer<MyStruct> structp = Pointer.malloc(MyStruct.SIZE, MyStruct.class); foo(Pointer.nref(structp)); structp.dref().some_field...;
20160831 08:01:58 <zubzub> /shameless advertising example of what you are trying to do
20160831 08:03:14 <bruce-> where is your osx and windows support? :)
20160831 08:03:26 <zubzub> patches welcome! :p
20160831 08:04:12 <bruce-> and what about JavaCPP?
20160831 08:04:31 <zubzub> mapping java to cpp is a nightmare
20160831 08:04:43 <zubzub> unless you deliberately limit the scope and functionality
20160831 08:04:57 <bruce-> but it maps cpp to java
20160831 08:05:35 <zubzub> no it maps java to cpp
20160831 08:06:56 <zubzub> also "Obviously, neatly supporting the whole of C++ would require more work (although one could argue about the intrinsic neatness of C++), but we are releasing it here as a proof of concept."
20160831 08:07:17 <zubzub> which covers my "10:04 < zubzub> unless you deliberately limit the scope and functionality" statement ;)
20160831 08:08:03 <zubzub> making something work 80% is 20% of the work
20160831 08:08:09 <zubzub> the other 20% is 80% of the work
20160831 08:09:08 <zubzub> but if osx & windows support will attract more users to my lib, I will try to make it work
20160831 08:21:07 <elect> I did read()
20160831 08:21:10 <elect> but still empty
20160831 08:21:26 <elect> empty as no values are set
20160831 08:21:30 <elect> vertex data is null
20160831 08:21:34 <elect> and vertex count is 0
20160831 08:22:34 <elect> what could be the problem?
20160831 08:23:32 <elect> if I do getPointer() I get this exc
20160831 08:23:33 <elect> Caused by: java.lang.IndexOutOfBoundsException: Bounds exceeds available space : size=8, offset=32
20160831 08:26:41 <zubzub> right so you create a pointerby reference
20160831 08:26:54 <zubzub> however in the C side you get a pointer of a pointer of something that was allocated right?
20160831 08:26:58 <zubzub> *cpp
20160831 08:27:12 <zubzub> where do you allocate the memory of the struct?
20160831 08:27:56 <zubzub> hmmm
20160831 08:27:59 <zubzub> in the cpp side
20160831 08:28:07 <zubzub> https://github.com/ValveSoftware/openvr/blob/master/samples/hellovr_opengl/hellovr_opengl_main.cpp#L1685-L1692
20160831 08:28:30 <zubzub> vr::RenderModel_t *pModel; will not allocate anything (I don't know Cpp very well)
20160831 08:28:34 <zubzub> ?
20160831 08:32:13 <zubzub> you can try allocating memory with the size of the struct
20160831 08:32:35 <zubzub> and pass a pointer of that allocated memory to the function
20160831 08:32:41 <zubzub> (ie a pointer to pointer)
20160831 08:33:24 <monsieur_max> mind blown
20160831 08:33:53 <zubzub> welcome to C :)
20160831 08:34:47 <monsieur_max> http://i.imgur.com/tOJKw.gif
20160831 08:37:55 <zubzub> elect: loading seems to happen async judging by the name
20160831 08:38:09 <zubzub> is perhaps the loading simply not yet finished?
20160831 08:38:29 <elect> no, because I keep polling
20160831 08:38:43 <elect> if it is not yet done I retrieve error = loading
20160831 08:38:55 <elect> when error = noError then it's done
20160831 08:39:43 <elect> you can try allocating memory with the size of the struct
20160831 08:39:48 <elect> >you can try allocating memory with the size of the struct
20160831 08:39:52 <elect> I had the same idea
20160831 08:40:11 <elect> try to allocare a pointer to memory of the struct size
20160831 08:40:24 <zubzub> yes
20160831 08:40:27 <elect> instantiate a new reference pointer passing the pointer
20160831 08:40:34 <zubzub> yup
20160831 08:40:37 <elect> give this refPtr to the load model
20160831 08:40:44 <elect> and see what shit I get back
20160831 08:40:47 <zubzub> yez
20160831 08:40:52 <elect> there is only a problem
20160831 08:40:56 <zubzub> you can try clearing out the memory first
20160831 08:41:00 <elect> I don't know a priori the model size
20160831 08:41:12 <zubzub> it's a opaque struct?
20160831 08:41:22 <elect> model contains also an array of vertices
20160831 08:41:27 <elect> and the count is unknown
20160831 08:41:45 <zubzub> C does nto have dynamically sized struct
20160831 08:41:57 <zubzub> the size is always known at compile time
20160831 08:42:08 <zubzub> if it has an array with a dynamic size
20160831 08:42:13 <zubzub> than it means it has a pointer to memory
20160831 08:42:26 <zubzub> and that memory is interpretd as an array
20160831 08:42:36 <zubzub> whose size is then stored in a field of that struct
20160831 08:42:40 <elect> LoadRenderModel must allocate the memory
20160831 08:42:47 <zubzub> ok
20160831 08:43:06 <zubzub> you can also not use pointerbyreference
20160831 08:43:15 <zubzub> and simply allocate new memory of size pointer
20160831 08:43:18 <elect> what do you suggest?
20160831 08:44:11 <zubzub> and pass that
20160831 08:44:18 <elect> and what will be that memory?
20160831 08:44:18 <zubzub> and see if the value changes
20160831 08:44:29 <elect> what shall I assign it too?
20160831 08:44:32 <zubzub> that memory will contain the addres of the struct
20160831 08:45:21 <zubzub> you can give the callback function simply a pointer to memory of size poitner (ie 8 bytes on 64 bit)
20160831 08:46:06 <zubzub> the callback function should then write an address (a 64 bit int) to the memory of that pointer
20160831 08:46:34 <elect> I tried to create a model reference
20160831 08:46:35 <elect> RenderModel_t.ByReference modelReference = new RenderModel_t.ByReference();
20160831 08:46:52 <elect> and use that to create the ref ptr
20160831 08:46:52 <elect> PointerByReference modelPtrRef = new PointerByReference(modelReference.getPointer());
20160831 08:47:07 <elect> LoadRenderModel_Async and then read() on both
20160831 08:47:19 <zubzub> I don't think that will work(?)
20160831 08:47:34 <elect> it doesnt indeed
20160831 08:47:36 <elect> ^^
20160831 08:47:41 <elect> but it should be
20160831 08:47:48 <elect> I am creating a pointer to model
20160831 08:47:56 <elect> and then I use that pointer to create another pointer
20160831 08:48:02 <elect> this is what they do on c++
20160831 08:48:18 <elect> by passing &model
20160831 08:48:26 <elect> where model was already a pointer
20160831 08:48:31 <zubzub> yes
20160831 08:48:49 <zubzub> so my advice is try passing it a simpel pointer of at least size 8
20160831 08:48:51 <zubzub> just that
20160831 08:48:52 <zubzub> nothing else
20160831 08:49:11 <elect> I cant instantiate a pointer wihtout passing the memory size
20160831 08:49:16 <elect> that's the problem
20160831 08:49:18 <zubzub> and see if the function writes an address
20160831 08:49:20 <zubzub> yes
20160831 08:49:22 <zubzub> size 8
20160831 08:49:25 <elect> uhm
20160831 08:50:27 <elect> Pointer modelPtr = new Memory(8);
20160831 08:50:32 <elect> error = renderModels.LoadRenderModel_Async.apply(stringPointer, modelPtr);
20160831 08:50:38 <elect> RenderModel_t m = new RenderModel_t(modelPtr);
20160831 08:50:38 <elect> m.read();
20160831 08:50:45 <elect> I get exc on the constructor
20160831 08:50:50 <elect> Caused by: java.lang.IllegalArgumentException: Structure exceeds provided memory bounds
20160831 08:50:59 <zubzub> yes because modelPtr is not a pointer of the model
20160831 08:51:03 <zubzub> but a pointer to pointer of a model
20160831 08:51:48 <elect> so I should do
20160831 08:51:48 <elect> RenderModel_t m = new RenderModel_t(modelPtr.getPointer(0));
20160831 08:51:49 <zubzub> the idea is to check if the function writes anything at all to your modelPtr (modelPtrPtr actually)
20160831 08:51:50 <elect> ?
20160831 08:51:52 <zubzub> yes
20160831 08:54:01 <elect> oh wait
20160831 08:54:04 <elect> I got an error
20160831 08:54:06 <elect> invalid model
20160831 08:54:09 <elect> wait wait
20160831 08:55:05 <elect> I got data
20160831 08:55:07 <elect> i love u
20160831 08:55:13 <zubzub> ^^
20160831 08:55:23 <elect> man this is funny
20160831 08:55:29 <elect> original jna coda
20160831 08:55:31 <elect> e
20160831 08:55:39 <elect> int apply(Pointer pchRenderModelName, PointerByReference ppRenderModel);
20160831 08:55:44 <elect> then I pass name as
20160831 08:55:47 * SHC (~quassel@anon) has joined #jogamp
20160831 08:56:01 <elect> Pointer stringPointer = new Memory(modelName.length());
20160831 08:56:03 <elect> ah wait
20160831 08:56:06 <elect> I only allocate that
20160831 08:56:08 <elect> shit
20160831 08:56:30 <elect> because if I change the name from Pointer to String
20160831 08:56:31 <elect> it works
20160831 08:57:44 <zubzub> if you use String jna will do the conversion from java string to c string (char pointer) for you in jni
20160831 08:58:05 <zubzub> which is slightly slower
20160831 08:58:11 <zubzub> but easier to use
20160831 08:59:10 <elect> I am an idiot, I was just allocating the pointer to the string
20160831 08:59:38 <elect> what I needed to do after was actually to write the shit string into the memory
20160831 08:59:39 <elect> stringPointer.setString(0, modelName);
20160831 08:59:55 <elect> and this crash
20160831 08:59:55 <elect> Pointer stringPointer = new Memory(modelName.length() + 1);
20160831 08:59:59 <elect> without the +1
20160831 09:00:06 <elect> it's the termination, isnt it?
20160831 09:00:09 <zubzub> yes
20160831 09:00:09 <elect> \0
20160831 09:00:15 <zubzub> yup
20160831 09:00:47 <elect> so, to sum up how it works now
20160831 09:00:54 <elect> Pointer modelPtr = new Memory(8);
20160831 09:00:59 <elect> error = renderModels.LoadRenderModel_Async.apply(stringPointer, modelPtr);
20160831 09:01:02 <elect> modelReference.read();
20160831 09:01:03 <elect> RenderModel_t m = new RenderModel_t(modelPtr.getPointer(0));
20160831 09:01:03 <elect> m.read();
20160831 09:01:05 <zubzub> try replacing the 8 with Pointer.SIZE or something
20160831 09:01:57 <elect> Pointer modelPtr = new Memory(Pointer.SIZE);
20160831 09:01:58 <elect> wotks
20160831 09:02:00 <elect> r
20160831 09:04:27 <elect> anyway, I'd like to get things straight now
20160831 09:06:16 <elect> oh god
20160831 09:06:19 <elect> it looks good now
20160831 09:06:30 <elect> tell me if it sounds logic
20160831 09:06:46 <elect> I create first a reference to the model
20160831 09:06:46 <elect> RenderModel_t.ByReference modelReference = new RenderModel_t.ByReference();
20160831 09:06:59 <elect> then I get the ptrptr
20160831 09:06:59 <elect> PointerByReference modelPtrRef = new PointerByReference(modelReference.getPointer());
20160831 09:07:09 <elect> I pass it to the function
20160831 09:07:09 <elect> error = renderModels.LoadRenderModel_Async.apply(stringPointer, modelPtrRef);
20160831 09:07:23 <elect> I read all
20160831 09:07:23 <elect> modelReference.read();
20160831 09:07:23 <elect> RenderModel_t m = new RenderModel_t(modelPtrRef.getValue());
20160831 09:07:23 <elect> m.read();
20160831 09:07:26 <elect> and then it works
20160831 09:07:41 <elect> this is how it should be, right?
20160831 09:08:02 <elect> because I have only one question
20160831 09:08:37 <elect> if I instantiate the RenderModel_t from the ptr, it doesnt really create a new copy
20160831 09:08:41 <zubzub> I think new RenderModel_t.ByReference() allocated memory
20160831 09:08:51 <zubzub> *allocates
20160831 09:09:12 <zubzub> which is not needed
20160831 09:09:15 <elect> rather it returns what has been already allocated by the LoadRenderModel_Async function
20160831 09:09:17 <elect> right=
20160831 09:09:22 <elect> ?
20160831 09:09:35 <zubzub> yes
20160831 09:09:45 <elect> you meister
20160831 09:10:27 <elect> anyway
20160831 09:10:48 <elect> it looks like modelReference.read() is not necessary
20160831 09:10:53 <elect> does it make sense?
20160831 09:11:03 <elect> because there are no field to read
20160831 09:11:04 <elect> ?
20160831 09:11:14 <elect> it's just a pointer..
20160831 09:12:30 <zubzub> I think modelReference is a pointer to (empty) allocated memory
20160831 09:12:39 <zubzub> I'm not sure if modelReference is needed
20160831 09:12:42 <elect> you can see the whole working code here
20160831 09:12:43 <elect> https://github.com/jovr/jogl-hello-vr/blob/master/jogl-hello-vr/src/helloVr/ModelsRender.java#L126-L146
20160831 09:13:20 <elect> I'd agree, I dont see any reason why c++ function wants a ** instead a simple *
20160831 09:13:41 <elect> maybe if you want to load multiple models?
20160831 09:14:16 <zubzub> cpp wants ** intstead of * because it probably wants to avoid copying everything it alloactes to your *
20160831 09:14:46 <bruce-> Model *model; allocateModel(&model);
20160831 09:15:26 <elect> however at the end they do
20160831 09:15:31 <elect> vr::VRRenderModels()->FreeRenderModel( pModel );
20160831 09:15:45 <elect> https://github.com/ValveSoftware/openvr/blob/master/samples/hellovr_opengl/hellovr_opengl_main.cpp#L1728
20160831 09:16:02 <zubzub> yes
20160831 09:16:12 <zubzub> because they only need the address for the free operation
20160831 09:17:53 <zubzub> the thing is that in C pointers are often used to return something
20160831 09:18:03 <zubzub> (instead of the function return value)
20160831 09:18:28 <zubzub> int foo; bar(&foo); //foo now has a value
20160831 09:18:44 <zubzub> int* foo; bar(&foo); //foo pointer now has a value
20160831 09:19:10 <zubzub> the type of a memory allocation is a pointer
20160831 09:19:25 <zubzub> so if bar wants to return a memory allocation to you
20160831 09:21:04 <zubzub> struct_foo* foo; bar(&foo); //foo pointer now has a value
20160831 11:57:42 <elect> zubzub,
20160831 11:58:00 <elect> do you have any idea how I may convert a ShortByReference to a short array?
20160831 11:58:15 <elect> because for a classByReference, I have toArray() method
20160831 11:58:25 <elect> from the Structure class
20160831 11:58:38 <elect> but ShortByReference don't extend the Structure class
20160831 11:58:38 <zubzub> a shortbyref is a pointer to a short
20160831 11:58:48 <zubzub> to have it as an java rray you have to know the size as well
20160831 11:58:53 <elect> I know
20160831 11:58:57 <elect> and I have it
20160831 11:59:08 <elect> do I have manually to traverse it?
20160831 11:59:29 <zubzub> that's one option, the other is to see how you can go from pointer to java array in jna
20160831 12:00:09 <zubzub> I don't know how to do that by heart
20160831 12:00:34 <elect> ah wait
20160831 12:00:35 <elect> found
20160831 12:00:35 <elect> model.rIndexData.getPointer().getShortArray
20160831 12:00:46 <elect> public short[] getShortArray(long offset, int arraySize)
20160831 13:19:35 * spaceemotion (~spaceemot@anon) has joined #jogamp
20160831 13:48:03 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 13:49:55 * juank_prada (~juank_pra@anon) Quit (Remote host closed the connection)
20160831 13:50:38 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 14:48:26 <elect> I just did it
20160831 14:48:28 <elect> https://github.com/jovr/jogl-hello-vr/blob/master/README.md
20160831 14:48:33 <elect> https://github.com/jovr/jogl-hello-vr
20160831 14:48:46 <elect> you can see also line and model controller
20160831 14:59:25 * elect (~elect@anon) Quit (Ping timeout: 255 seconds)
20160831 15:39:55 * SHC (~quassel@anon) Quit (Read error: Connection reset by peer)
20160831 15:40:12 * SHC (~quassel@anon) has joined #jogamp
20160831 15:57:39 * monsieur_max (~maxime@anon) Quit (Quit: Leaving.)
20160831 16:06:52 * jvanek (jvanek@anon) Quit (Quit: Leaving)
20160831 16:45:57 * monsieur_max (~maxime@anon) has joined #jogamp
20160831 17:22:02 * SHC (~quassel@anon) Quit (Remote host closed the connection)
20160831 17:26:19 * juank_prada (~juank_pra@anon) Quit (Remote host closed the connection)
20160831 17:39:42 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 18:04:35 * i-make-robots (~dan@anon) has joined #jogamp
20160831 18:04:53 <i-make-robots> hi jogamp. I'm getting an exception and I don't know what it means. can you please give me a hint? https://github.com/MarginallyClever/Robot-Overlord-App/issues/24
20160831 18:26:42 * juank_prada (~juank_pra@anon) Quit (Remote host closed the connection)
20160831 18:58:33 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 19:33:59 * juank_prada (~juank_pra@anon) Quit (Remote host closed the connection)
20160831 20:58:50 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 21:00:50 * monsieur_max (~maxime@anon) Quit (Quit: Leaving.)
20160831 21:03:07 * juank_prada (~juank_pra@anon) Quit (Ping timeout: 252 seconds)
20160831 21:55:10 * juank_prada (~juank_pra@anon) has joined #jogamp
20160831 21:59:46 * juank_prada (~juank_pra@anon) Quit (Ping timeout: 244 seconds)
20160901 00:51:57 * spaceemotion (~spaceemot@anon) Quit (Quit: Textual IRC Client: www.textualapp.com)
20160901 02:30:03 * juank_prada (~juank_pra@anon) has joined #jogamp
20160901 04:36:55 * juank_ (~juank_pra@anon) has joined #jogamp
20160901 04:38:12 * juank_prada (~juank_pra@anon) Quit (Ping timeout: 240 seconds)
20160901 04:38:28 * bigpet (uid25664@anon) Quit (Read error: Connection reset by peer)
20160901 04:40:45 * bigpet (uid25664@anon) has joined #jogamp
20160901 04:45:38 * juank_ (~juank_pra@anon) Quit (Remote host closed the connection)
20160901 05:05:11 -jogamp- Continue @ http://jogamp.org/log/irc/jogamp_20160901050511.html