hey @Sean is there any python interface of brlcad or any python files in the project?
if there isnt any, should i try adding a feature in python :slight_smile: ?(i will start contributing in C++/C )
@Sumagna Das there is an unofficial python interface from a couple years ago that you can find by searching. there's a development version not committed yet to the repo, which you can find in our patches tracker. You could contribute by applying that to current trunk sources, make any changes necessary to get it working again.
@Sean Where to search for that? Can you give me a link to the patches
tracker?
Sumagna Das said:
@Sean Where to search for that? Can you give me a link to the patches
tracker?
@Sumagna Das how have you tried looking for it?
I don't know where to start looking from
heh, really? so you're saying you don't know how to search for things?
I don't mean to say that
I just don't know where to look for
so you're saying you know how to search for things but don't know where to search for things? I'm not sure I understand how that's possible. please explain.
Okay
I am going to try and search in places I can find
Sean said:
Sumagna Das there is an unofficial python interface from a couple years ago that you can find by searching. there's a development version not committed yet to the repo, which you can find in our patches tracker. You could contribute by applying that to current trunk sources, make any changes necessary to get it working again.
@Sean i found the patch, is that all?
I couldn't complete my message earlier
there's an unofficial python interface AND there's a patch, they are separate things. glad you found the patch as that was the part that you could review and try to get working on the latest sources
So they are seperate things. Thanks for the info.
@Sean By unofficial, you mean, that I will not find it in the source forge repo?
hey @Sean, is this the one you were talking about?
https://brlcad.org/wiki/User:Krajkreddy/GSOC14/proposal
the unofficial python interface?
i also found a pip package related to this
python-brlcad
Sumagna Das said:
Sean By unofficial, you mean, that I will not find it in the source forge repo?
Correct.
And the unofficial one is the pip package you found from kanzure.
i found the inerface you were talking about, i think
but i dont think i found the right patch in the patches tracker
why do you say that?
i got a patch called superell.patch
is that the one you were talking about?
where did you get that from?
https://sourceforge.net/p/brlcad/patches/277/
:shock:
I don't see any mention of python whatsoever
i searched for python and it returned this
ah, that's because I was mistaken -- it's right there in the description.
hmm
hold on, let me look
So, here's a good write-up on the python interface -- you could try and see if you can get it working by yourself: https://medium.com/@Mr_Jaypee/brl-cads-python-procedural-geometry-990e3c286a63
This was the most recent work: https://github.com/Killthebug/python-brlcad/
Log of that work is here: https://brlcad.org/wiki/User:Schindler97/GSoC18/Log
i would try my best to get it working if i can
i have to go in a few minutes
i have classes tomorrow so before that i will take a look in the above links
or else tomorrow
it looks like the one pending patch I was thinking of is already integrated, so nothing to do there. the other one appears to be on that github repo
the other one?
you question is incomplete
Sean said:
it looks like the one pending patch I was thinking of is already integrated, so nothing to do there. the other one appears to be on that github repo
what is "the other one"?
the other patch I was thinking of appears to be that github repo
it was a gsoc project two years ago
oh ok
i have a far-fetched idea
should i try making a GUI?
haha. no.
i am practicing pyqt(PySide2)
ok no problem
that's so much more complexity to create something useful
i can understand
let me ask you, what are you trying to accomplish?
what would you like to do? why did you mention python in the first place?
are you looking to take on a project?
i wanted to contribute to brlcad using python
nope
why?
why "using python"?
i am much more comfortable now in python
but how are you looking to contribute? towards what end?
i thought if there's a python interface of brl-cad, i would contribute to that
or else try to make one(if i could)
you just repeated yourself without answering the question :)
ok
how are you looking to contribute? towards what end?
you said you would contribute to "that" -- presumably "that" is the python interface itself? or create something using python? or model with python? or improve the ability to work with python in brl-cad? or ... ???
i wanted to improve the ability to work with python in brl-cad
so there's two ways you can do that. there's a "script" entity type inside BRL-CAD that could be improved and there's a python interface outside BRL-CAD that could be improved.
what is "script"?
the inside one requires that you have basic understanding of BRL-CAD's tools
ok
then i would start contributing to the outside one first
@Sumagna Das you're asking such fundamental questions that I really recommend you first complete tutorials so you at least have a basic understanding of terms
have you done the MGED tutorials?
yeah, i think so
then you should know what a script entity probably refers to... just like there are ell and sph and arb8 entities, there is a script entity
entity = object
i confused entity with something else
sorry
the general idea is a user can create an object that is a python script that defines how that object behaves. this interface does not yet exist, but would be a goal.
the script creates geometry and is called by C code on the fly
that's for the work inside BRL-CAD
for the python work outside BRL-CAD, the approach is very different. You should read the links I provided or you will not be able to help with it.
ok
I'd start with https://medium.com/@Mr_Jaypee/brl-cads-python-procedural-geometry-990e3c286a63
and get it working on your computer.
i am going to sleep right now as i have school
i will test that tomorrow
If you can't get it working, then you might not have enough background -- you might want to pick a much simpler goal, which I would recommend regardless just to get familiarized.
like?
what goal can you recommend to me right now to get familiarised?
like starting with a simple tcl script that creates some geomtry
it will be much helpful
using mged commands
what's a shape or object that you want to model?
asking me or saying to me?
asking
umm... i dont have a answer for that right now
for example, you could try to model this: https://brlcad.org/gci/ideas/puzzle/puzzle.jpg
thats nice
i would like to try that
model it yourself first, maybe redo the tutorials if you forgot all the commands
alongside that i can try making the python-brlcad work
then once you have done that, you could try turning it into a script
ooh
thats a nice idea
once you have it in a script, you could try turning it into a python script
i do things like that now
first script would be an mged script, also known as a tcl script
i saw shell scripting
i can somewhat convert a sh file to python(not much confident about that)
you can script mged itself externally with anything including a shell script
thats nice
i would do shell scripting rather than tcl
you could use python today, but you don't know the mged commands
i know shell but not tcl
hmm
you're getting far too caught up in the language if you ask me
yea
i first want to be confident about python then start learning another language
like I said, you are lacking on some basics first. if you don't learn them, you won't be able to do these more advanced ideas
you write commands to create geometry.. there are hundreds of commands in BRL-CAD
hmm
those commands can be created from any language
you're wanting to use python, but you don't know the commands yet
i gotta go after the source code of the brl cad has been downloaded
so I recommend learning some of the commands first by creating some geometry like that cube example
i would do that
compile brl-cad, run mged or archer, and create that "dice" model
keep notes on what commands you used to create the dice model
what steps you do
i will write them down on txt file
good luck
in the meanwhile should i try getting python-brlcad to work on my computer?
you're welcome to try, but based on your questions I honestly do not think you will be successful without lots of help
whom can i take help about this from?
you can ask here, that's not the point
ok
the point is that it is going to take you a very long time and will likely be frustrating or confusing or "hard"
you're going to have to read a lot, and you don't seem very inclined to read a lot...
why do u say that?
some people like to be told what to do, others are good at discovering things on their own
i am a middle man
i discover things on my own but sometimes i need to be told what to do
if you need it even sometimes, then you're the first type
that can be so
people good at discovery can figure out almost any problem given enough time and motivation, they discover how on their own even when they do not know
it's a good skill to practice
i am trying to do that as much as i can
that said, your skills are young, so you still need to have realistic goals or you'll just get frustrated
what do u mean by realistic goals?
if you told me that you wanted to model your car in 3D
with enough accuracy that it could be manufactured or even just 3D printed faithfully
that would not be a realistic goal
i could not think of anything other than some sleep
i would go to sleep after the build of brl-cad is finished
there's plenty of time to sleep after we die ;)
:lol:
i am trying to do as much programming and contributing this year as i can do because next year i wouldnt get much time
i have to study almost all of the day
how much time can brl-cad take to build
okay good night everyone
see you tomorrow
I thought, the point with BRL-CAD's Python interface is that the current one is Python 2.x based, which will reach its end of life soon and is deprecated therefore. I.e. the task would be to write a Python 3.x interface.
I will try my best at that
As you have already discussed with Sean: This is not a trivial task. I t means to program most of the time in C or C++, not Python. It means to implement the piece of code, which a programmer can use in Python, not the Python code itself.
i was fixing the code for the python interface
it cannot find nurb.h
in which folder is it stored
Maybe, we don't have this header anymore.
probably replaced or removed
is it replaced by opennurbs?
I would expect this.
i didnt understand
I think that this is a header for the predecessor of openNURBS, but I'm not sure.
ok
i was trying to fix the python interface outside brl cad
my computer cannot handle brl cad rendering right now so i will do the inner interface later
BTW, I don't think that this is the right way to do it. In my opinion, the whole interface has to be rewritten. There are many changes in the BRL-CAD API too.
This means, you should start with designing the Python interface. I.e., how should the Python functions look like? To answer this, you have to learn more about APIs and interfaces in general.
Sean showed you a way to do this: Find a problem which shall be solved with Python. E.g., model a puzzle. (You can model other things too, if you like.) The curse of action would be the following:
When you have done this, you learned a lot about BRL-CAD interfaces and you may have an idea of how the one to Python should look like.
ok
Daniel Rossberg said:
BTW, I don't think that this is the right way to do it. In my opinion, the whole interface has to be rewritten. There are many changes in the BRL-CAD API too.
This means, you should start with designing the Python interface. I.e., how should the Python functions look like? To answer this, you have to learn more about APIs and interfaces in general.
Sean showed you a way to do this: Find a problem which shall be solved with Python. E.g., model a puzzle. (You can model other things too, if you like.) The curse of action would be the following:
- Model the geometry as usual in mged or archer.
- Write a program which utilizes the BRL-CAD C API to model the geometry. In src/proc-db are a lot of programs which are doing such kind of tasks. You can put your own program in this directory too (in your own copy).
- Write a TCL program which runs in mged to model the geometry.
- Write a program which utilizes the BRL-CAD core C++ interface to model the geometry. This interface can be found in the rt^3 repository branch. In tests/coreInterface you find examples of such programs.
- Write a Lua program to model the geometry. The Lua interface can be found in the rt^3 branch too. In tests/embeddedLua are example programs.
When you have done this, you learned a lot about BRL-CAD interfaces and you may have an idea of how the one to Python should look like.
and also i have this year's time as i will not be doing anything much next year(i will continue contributing the year after the next one)
@Daniel Rossberg should i use the old python-interface as a base?
This is one possibility, to "simply" port the interface from Python 2.x to 3.x. But, I'm afraid that this is not simple because of API changes. And, there were a lot of issues with the old interface too. I.e., you can try to do so, but a restart could be easier.
it seems so
i tried fixing eveything but it was very much tough and still it isnt 1% fixed
what is the main library in Brl-cad?
which nearly include all the functions for making shapes?
i am going to try to restart the whole thing
In my opinion, it's worth to dive deeper into the different kinds of BRL-CAD programming. It may feel as being not productive, but learning about the different interface designs is very helpful if you want to design an own one.
i will do that first, mainly the c++ one
i had an introduction in that one in 2019 gci
Most people consider librt as the main library, but libwdb is used to create the database entries.
ok
There are two main designs for the interfaces:
I am going to do something like the first one
Then, if it's necessary, I will make a command line interface(if that's what you tried to mean in the second way)
It's your decision. Which of the two would look more Python-like?
First one
The ctypesgen interface does utilize an object-oriented design, if I recall correctly. It low-level binds into libwdb, but then presents a database and object API, not a command API like ged.
here's an example https://github.com/kanzure/python-brlcad/blob/master/examples/wdb_globe.py
not the cleanest, the args are nearly a pass-through to the C api, but definitely a bit closer to objects than commands in style. not an example to necessarily repeat, but an interesting study
@Sean can i use the old python interface as a base for the newer python package?
what are the libraries required to access the BRL-CAD core interface?
Do you see the TARGET_LINK_LIBRARIES in rt^3/src/coreInterface/CMakeLists.txt?
lemme see
so i was trying to use ctypesgen to generate a py file from all the header files in include/brlcad/rt folder
(deleted)
(deleted)
hey @Sean, do u know how to use ctypesgen command to get the macro definitions?
i was trying out the ctypesgen command to convert raytrace.h, vmath.h and common.h to write the rtexample.c in python
but ctypesgen couldnt convert macro definitions
btw it somewhat works
So an update about the python interface
Everything is working fine except the macro definitions
I was trying to convert rtexample.c to rtexample.py using the ctypes wrappers but the many of the macro definitions are not available so it is hard as I am having to redefine them as functions in the python file
So what should I do about it?
I am still trying to make the macro definitions work
macros don't exist to the compiler, so you may not have an alternative except wrapping them in functions or using alternative functions (many already have an alternate C function)
that's pretty cool that you got as far as you did @Sumagna Das -- can you show a screenshot and code example where it's at?
most of the vmath stuff I would expect to be available in other existing python packages -- that's basic math
that just leaves a few to worry about which aren't critical and/or have function alternatives. Case by case..
I will push the code to GitHub
And the screenshot I will give to you later
By the way, I haven't organized the code
So it might be a bit harder to read
The GitHub link is https://github.com/sumagnadas/python-brlcad
hey @Sean i am also creating a parser which parses the macros into normal python functions(not ctypes.CFUNCTYPE)
i have to see whether it gets all the macros or misses some of them
what are the back slashes for at end of some of the lines in some macros?
i have to pause the work on the interface right now because of my school and some personal problems.
i will resume the work from next week onwards
rtexample-and-rtexample.py.png
the screenshot of the working of the python file
it is somewhat working because i couldnt make the macros(converted to python functions) work so some of the calculations are wrong
or else all of the things are printed using bu_log and VPRINT
this is the file
this file contains almost all of the macros. it was mostly made using a parsing python script i had made.
umm do i need all the macros or do i need the most useful?
so another update about the interface
i made the example specified in this link: https://medium.com/@Mr_Jaypee/brl-cads-python-procedural-geometry-990e3c286a63 and it was succesful
here's the screenshot of the shape i made using my code example.png
Sumagna Das said:
what are the back slashes for at end of some of the lines in some macros?
Same as it is elsewhere in C. Those are line continuations. It's how you have a macro that's effectively multiple lines of logic.
Okay
I was trying to parse them but it was hard so I left the parser
@Sumagna Das that rtexample.py you wrote is impressive! I think it shows a lot of the limitations of doing a direct conversion from C to Py, but it clearly works. Do you think you could create a fake rtexample that is 'ideal', what you think the python interface should look like?
because the direct conversion feels very low-level to me, too low-level. That if I were to design a python API from scratch, I probably would create a raytracing example differently.
If you could mock it out, we could look at what changes might be needed, either on the C/C++ side or as a higher layer in python.
Here's a good example of a more pure object approach using the MOOSE API: https://brlcad.org/wiki/CoreInterface_Hallo_World_Example
ok
i will try
i just wanted to show through that example that the bindings work
i made another example using wdb
please see to that and tell me how it is
later i would make classes very much similar to the previous interfaces
Sumagna Das said:
i just wanted to show through that example that the bindings work
yeah, no don't get me wrong -- that's amazing!
you're on python 2 yes?
i can underdstand what you wanted to say
no python3
python 3.8
using ctypesgen?
yea
huh, so someone must have finally fixed it, updated it?
ctypesgen?
do you mean someone fixed ctypesgen?
if you mean ctypesgen, its latest update on pip was in december 2019 and latest commit on github repo is in march 2020
wow, so then yeah.. really recent. it was broken for python3 for years. that's why the python work stalled. the entire approach relied on it.
so then since you're looking at it... do you think you could review https://github.com/kanzure/python-brlcad and its forks to merge everyone's efforts @Sumagna Das?
https://github.com/Killthebug/python-brlcad in particular has the latest but there are at least two other forks that have commits ahead of kanzure's:
https://github.com/kanzure/python-brlcad/network/members
Sean said:
so then since you're looking at it... do you think you could review https://github.com/kanzure/python-brlcad and its forks to merge everyone's efforts Sumagna Das?
https://github.com/Killthebug/python-brlcad in particular has the latest but there are at least two other forks that have commits ahead of kanzure's:
i will do that after i make the pip package for the python interface or something like that
Sean said:
Here's a good example of a more pure object approach using the MOOSE API: https://brlcad.org/wiki/CoreInterface_Hallo_World_Example
this is rt^3, right?
In general, yes. Headers are in include/brlcad and sources in src/coreInterface. But this is the C++ core interface. For a MOOSE version see https://github.com/drossberg/MOOSE. From the programmers point of view, they are very much the same. For the moment, it doesn't matter which one you use. With Visual Studio you can use the brlcad.dll too (https://sourceforge.net/projects/brlcad/files/BRL-CAD%20Runtime%20Libraries/7.26.0/brlcad-7.26.0_dll_devel.zip/download).
ok then
yeah, I'm considering them one in the same. MOOSE == core interface ;)
i was seeing KilltheBug's repo on python-brlcad
i saw that he used numpy for vmath
so should i do something similar?
It's not a bad way to go about it. vmath is basic math so using something already in python is probably preferable to transcoding vmath to python
ok
is there a list or something like that which can tell me what are the important vmath function from vmath.h?
you could grep for them all and count up their usage
counting them now with:
grep 'define[^d]' include/vmath.h | grep '#' | sed 's/.*define[[:space:]]\([A-Z0-9_]*\).*/\1/g' | while read symbol ; do echo -n "$symbol " ; grep -r -I -E "[^a-zA-Z0-9_]$symbol[^a-zA-Z0-9_]" include src/[^o]* 2>/dev/null | wc -l ; done | sort -n
Sean said:
counting them now with:
grep 'define[^d]' include/vmath.h | grep '#' | sed 's/.*define[[:space:]]\([A-Z0-9_]*\).*/\1/g' | while read symbol ; do echo -n "$symbol " ; grep -r -I -E "[^a-zA-Z0-9_]$symbol[^a-zA-Z0-9_]" include src/[^o]* 2>/dev/null | wc -l ; done | sort -n
thanks for the command
going to work on vmath next with numpy
then try to make a much more organized python file for calling the modules
here's the ones that are called at least 100 times:
4425 VMOVE
3131 VSET
2092 VSCALE
1646 V3ARGS
1579 VSUB2
1485 MAT4X3PNT
1294 VDOT
1229 VJOIN1
1182 VUNITIZE
1089 VADD2
1075 MAGNITUDE
1044 ZERO
770 VSETALL
731 NEAR_ZERO
678 VCROSS
651 SMALL_FASTF
546 MAT_IDN
520 INFINITY
517 MAT4X3VEC
501 VINIT_ZERO
499 VPRINT
459 ELEMENTS_PER_VECT
433 NEAR_EQUAL
430 EQUAL
409 VJOIN2
380 MAT_COPY
359 INTCLAMP
348 VREVERSE
308 MAX_FASTF
300 DEG2RAD
284 VMINMAX
276 V_MAX
262 MAGSQ
249 ELEMENTS_PER_POINT
237 V_MIN
226 M_PI
206 M_2PI
202 V2MOVE
195 SQRT_SMALL_FASTF
167 V2SET
154 RAD2DEG
130 VUNITIZE_TOL
129 VADD3
108 VNEAR_EQUAL
not to say that the ones called fewer times aren't important too, but it gives an idea of the utilization
also note that some usages are in other macros which themselves might be used hundreds/thousands of times. I didn't try to count that, but it'd be a similar counting process to identify usage in include/ and look for those indirect calls
I used a script to parse the macros into functions
Some of them worked
Others have to be fixed
@Sumagna Das but why?? that means it will be out of sync the instant anyone makes a change to vmath.h ... it does change from time to time.
that i have to see to
that is the issue i had
because of that i didnt use that file nor the (somewhat) parser
I discarded that idea
@Sumagna Das so what's next?
I don't know right now
There's a storm raging outside
It will continue until tomorrow morning I think
yikes, hope you don't loose power
Actually the power is cut off for 7 or 8 hours now
yikes, sorry to hear that @Sumagna Das
My father told me that it will be back by tomorrow morning
Its 1 in midnight
So I don't think I will be back on the interface at least for this week
So I will not be back on the interface for a couple of days
Internet is not working here
@Sumagna Das how are you on chat then? is there anything I can do to help?
Wifi is not available. I am online through cellular net which is very very
slow.
Wifi will be back after three days or so
Hey @Sean my net is coming back after a few days(it is working well right now, though it is midnight) so I think I will be back when it comes back
The cyclone did too much damage to internet and cellular networks
Sean said:
Sumagna Das that rtexample.py you wrote is impressive! I think it shows a lot of the limitations of doing a direct conversion from C to Py, but it clearly works. Do you think you could create a fake rtexample that is 'ideal', what you think the python interface should look like?
As you said, i created a fake example, wdbexample(as it was easier to make than rtexample) in python to demonstrate the use of the prototype python interface. Right now, it only includes a Database class(yes, i somewhat copied it from the previous python interface) with support to make a sphere. The use of Database class is demonstrated in wdbexample.py file.
So @Sean, what do you think about it?
@Sumagna Das Where's the wdbexample code? I saw the rtexample but not wdb one...
It's pretty amazing that you got it all working again. Seriously, the python interface stalled for years because ctypesgen hadn't been ported to python3.
So next, would be a question on where you want to take this next? I know what I'd love to see but would rather hear your interests and ideas first.
Sean said:
Sumagna Das Where's the wdbexample code? I saw the rtexample but not wdb one...
if you mean C code for the wdexample, then its not ported from c but a new file showing the working of libwdb or wdb.h in a more organized looking way.
you said you created a fake example, wdbexample -- I've not seen this example
Sean said:
you said you created a fake example, wdbexample -- I've not seen this example
an example in python (actually not present in c files) showing the prototype working of the python interface
Sean said:
So next, would be a question on where you want to take this next? I know what I'd love to see but would rather hear your interests and ideas first.
Tell me what you would like to see. i will try to implement that. i am very much confused as to what to do next
We would like to hear your ideas and vision and interest, we want to craft this experience to be beneficial to both parties , not "just a job".
:smile:
i was thinking about creating a prototype rtexample in python(which isn't a direct connversion from C to Python)
BTW, what is the "magic" variable in nearly every struct used for?
It's a number stashed at the beginning to help deduce type, common in programming language implementations
ohh
Bualloca also stashes a little magic up front to help with memory mgmt
its just a number then?
Yes, and arbitrary. They should be #defined in headers if you want to peruse
i was going to port vmath.h functions in a python file using numpy
Should I complete the Database class first or should I try implementing the raytracing interface?
hey @Sean, what is libbn for?
@Sumagna Das A brief description of all the libraries is in HACKING. bn is for numerics.
ok
Sumagna Das said:
Should I complete the Database class first or should I try implementing the raytracing interface?
what should i do first?
hey @Sean, what information is most required when a ray hits something during raytracing.
@Sumagna Das The magic numbers definitely shouldn't be translated to python. They are an artifice of C programming, they primarily are used to catch low-level memory corruption.
Sumagna Das said:
Sumagna Das said:
Should I complete the Database class first or should I try implementing the raytracing interface?
what should i do first?
I would think Database would be more desirable first. Ability to create stuff using python scripts cleanly.
Sumagna Das said:
hey Sean, what information is most required when a ray hits something during raytracing.
This very much depends on the person or application shooting the rays. It could be almost anything. Some care about the first hit point, some care about the thickness of the things hit, some care about the curvature of the surface at the entry or exit hit point, some care how many things were hit, some want to know whether two objects are in proximity or overlap, etc ...
Sean said:
Sumagna Das said:
hey Sean, what information is most required when a ray hits something during raytracing.
This very much depends on the person or application shooting the rays. It could be almost anything. Some care about the first hit point, some care about the thickness of the things hit, some care about the curvature of the surface at the entry or exit hit point, some care how many things were hit, some want to know whether two objects are in proximity or overlap, etc ...
should i see to the rtexample for the information i can send during raytracing?
@Sumagna Das that's part why I suggested Database first .. ray tracing is an order of magnitude more complicated...
okay
but if that's what's more interesting to you,rtexample is as good a place as any to start. it shows hit points, thicknesses, and normals
okay
@Sumagna Das which repo of ctypesgen are you using ? I had forked from https://github.com/olsonse/ctypesgen and did some changes, for py3 but I think olsonse's repo now support py3 :)
scorp08 said:
Sumagna Das which repo of ctypesgen are you using ? I had forked from https://github.com/olsonse/ctypesgen and did some changes, for py3 but I think olsonse's repo now support py3 :slight_smile:
https://github.com/davidjamesca/ctypesgen
they are even
which function in wdb can be used to open existing geometry databases?
@Sean i got this error while trying to make a combination
ERROR: bad pointer 0x1bf5bb0: s/b rt_comb_internal(x436f6d49), was Unknown_Magic(x22af6f0), file /mnt/sda2/github/brlcad/src/librt/comb/comb.c, line 284
what is happening?
Sumagna Das said:
ERROR: bad pointer 0x1bf5bb0: s/b rt_comb_internal(x436f6d49), was Unknown_Magic(x22af6f0), file /mnt/sda2/github/brlcad/src/librt/comb/comb.c, line 284
hey @Daniel Rossberg can you help me with this?
It looks like you made an error, but I've no idea what you made.
what can it be related to?
what is Unknown_Magic anyways?
It means that you put an object in a function which expects a combination which was in fact no combination.
ok
i have to check the code then
hey @LordOfBikes why is this coming
ERROR: bad pointer 0x1be4200: s/b union tree(x91191191), was Unknown_Magic(x5f687073), file /mnt/sda2/github/brlcad/src/librt/comb/comb.c, line 93
or can you tell me what should be the magic number for the union called "tree"
Hi @Sumagna Das , sadly I cant help here. I'm a LibreCAD maintainer and do not have sound knowledge of BRL-CAD code base.
hey @Sean can you see a backtrace i got and tell me if this is a fault with my code in python(i am calling wdb_export) or this is a fault in the brlcad code?
Sumagna Das said:
hey Sean can you see a backtrace i got and tell me if this is a fault with my code in python(i am calling wdb_export) or this is a fault in the brlcad code?
hey @Daniel Rossberg can you help me with this?
I can't say more as I already did without more information: You probably made an error and used a bad parameter in a function.
should i send the backtrace
This would be a start point.
Where is your source code?
python source code?
Whatever you have written to get it working with Python.
(deleted)
Daniel Rossberg said:
Whatever you have written to get it working with Python.
sorry for the late reply. i didnt push the changes to my repo.
i have to code at https://github.com/sumagnadas/python-brlcad
it has the bindings pregenerated and libraries set to default locations(like /usr/brlcad/dev-7.31.0/lib/)
so it might be a problem
Do you have the back-trace too?
yea
got it from gdb(as per StackOverflow) as it was giving a SIGSEGV
should i send it?
AS far as I can see, this should happen when you create a combination?
yea when i am trying to use wdb_export for making a combination(i dont know if i need it)
#0 __memcmp_sse4_1 () at ../sysdeps/x86_64/multiarch/memcmp-sse4.S:73
#1 0x00007fffe9f9f5ce in bn_mat_is_identity (m=0x736772615f) at /mnt/sda2/github/brlcad/src/libbn/mat.c:992
#2 0x00007fffea876d12 in db_tree_counter (tp=0xdc9400, tcsp=0x7fffffffc8f0) at /mnt/sda2/github/brlcad/src/librt/comb/comb.c:99
#3 0x00007fffea87788a in rt_comb_export5 (ep=0x7fffffffc9e0, ip=0x7fffffffcaa0, UNUSED_local2mm=1, dbip=0xd53640,
resp=0x7fffeac88f00 <rt_uniresource>) at /mnt/sda2/github/brlcad/src/librt/comb/comb.c:292
#4 0x00007fffea88fd1b in rt_db_cvt_to_external5 (ext=0x7fffffffca40, name=0x7fffe6750410 "sph_with_args_region", ip=0x7fffffffcaa0, conv2mm=1,
dbip=0xd53640, resp=0x7fffeac88f00 <rt_uniresource>, major=1) at /mnt/sda2/github/brlcad/src/librt/db5_io.c:663
#5 0x00007fffeabf013f in wdb_put_internal (wdbp=0xd74070, name=0x7fffe6750410 "sph_with_args_region", ip=0x7fffffffcaa0, local2mm=1)
at /mnt/sda2/github/brlcad/src/librt/wdb.c:246
#6 0x00007fffeabf038d in wdb_export (wdbp=0xd74070, name=0x7fffe6750410 "sph_with_args_region", gp=0xb03a60, id=31, local2mm=1)
at /mnt/sda2/github/brlcad/src/librt/wdb.c:293
#7 0x00007ffff7fbeff5 in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
#8 0x00007ffff7fbe40a in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
#9 0x00007ffff752e69c in _ctypes_callproc () from /usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so
#10 0x00007ffff752ec9c in ?? () from /usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so
#11 0x00000000005f2246 in _PyObject_MakeTpCall ()
#12 0x000000000056c70f in _PyEval_EvalFrameDefault ()
#13 0x00000000005654d2 in _PyEval_EvalCodeWithName ()
#14 0x00000000005f1bc5 in _PyFunction_Vectorcall ()
#15 0x0000000000508386 in ?? ()
#16 0x00000000005f0e3e in PyObject_Call ()
#17 0x0000000000568985 in _PyEval_EvalFrameDefault ()
#18 0x00000000005654d2 in _PyEval_EvalCodeWithName ()
#19 0x0000000000507e8f in ?? ()
#20 0x0000000000568404 in _PyEval_EvalFrameDefault ()
#21 0x00000000005654d2 in _PyEval_EvalCodeWithName ()
#22 0x0000000000686d53 in PyEval_EvalCode ()
#23 0x0000000000676101 in ?? ()
#24 0x000000000067617f in ?? ()
#25 0x0000000000676237 in PyRun_FileExFlags ()
#26 0x00000000006782ba in PyRun_SimpleFileExFlags ()
#27 0x00000000006af5ce in Py_RunMain ()
#28 0x00000000006af959 in Py_BytesMain ()
#29 0x00007ffff7de10b3 in __libc_start_main (main=0x4ec640 <main>, argc=2, argv=0x7fffffffdae8, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffdad8) at ../csu/libc-start.c:308
#30 0x00000000005f69be in _start ()
this is the backtrace
so i was seeing mk_region1() arguments
what should be an ideal value for rgb?
i mean this one const unsigned char * rgb
Using wdb_export() is okay, The error is probable in the new_comb structure or how it is transferred to the C functions. What says the debugger about ip->idb_ptr in rt_comb_export5()? How does it look?
Daniel Rossberg said:
Using wdb_export() is okay, The error is probable in the new_comb structure or how it is transferred to the C functions. What says the debugger about ip->idb_ptr in rt_comb_export5()? How does it look?
how to see that?
break rt_comb_export5
in gdb? Step to line 284 and do a print comb
there? (I haven't tested it and I'm not very used in using gdb, but it should work somehow like this.)
it is giving me this (struct rt_comb_internal *) 0xdb2970
this is before stepping to line 284
because print comb
doesnt work there
comb is assigned at line 283. That's why you have to go to line 284 first to step over 283 and get this assignment.
However, how are the members of rt_comb_internal doing? can you attach them to the printed variable (by "->member_name")?
print ip->idb_ptr
gives me (void *) 0x0
NULL is not enough ;)
what?
rt_comb_export5() got NULL as input, this is not enough to create a combination.
ok
sorry gotta go
my laptop has 3% charge
Now, you should go up the call stack in gdb to the wdb_export() function and look what it got from Python (I think it's the frame
command).
Sumagna Das said:
my laptop has 3% charge
Okay, bye...
Daniel Rossberg said:
Now, you should go up the call stack in gdb to the wdb_export() function and look what it got from Python (I think it's the
frame
command).
went up the call stack but what should i specifically look for?
i looked at gp and got "ImoC"
What is "ImoC"?
dont know but i found an interesting thing
i have struct tree_db_leaf whose tl_mat is None
for which there is an error happening whenever bn_mat_is_identity(tp->tr_l.tl_mat))
is called
Sumagna Das said:
for which there is an error happening whenever
bn_mat_is_identity(tp->tr_l.tl_mat))
is called
This shouldn't be an issue because it is tested for NULL before.
oh sorry wrong line
this is where the error occurs return ! memcmp(m, bn_mat_identity, sizeof(mat_t));
m is NULL so the error is coming?
It should not call bn_mat_is_identity() if the matrix is NULL. Therefore, what do you mean with "tl_mat is None"?
tl_mat is actually NULL
None = NULL
In this case, bn_mat_is_identity() wan't be called and there can't be an error.
so what should i do?
It looks like the structure you hand over to wdb_export() is not what you think it is. Break at wdb_export(), check that gp is not NULL, then cast it to rt_comb_internal*, and examine it.
sorry if i am asking a stupid question but how to check if its NULL
print gp
should be something like 0x000000.
Nope
(struct rt_comb_internal *) 0xb03a50
which means it is not NULL
(void *) 0xb03a50
when print gp
is used
What gives you print ((rt_comb_internal*)gp)->magic
?
1131375945
or more specifically 0x436f6d49
Is this the right number for a combination?
how can i know?
should that be RT_COMB_MAGIC?
BTW, if gp is 0xb03a50 in wdb_export(), then ip->idb_ptr in wdb_put_internal() should be 0xb03a50 too, right?
lemme see
print ip->idb_ptr
gives (void *) 0xb03a50
so yeah they are same
But, this value should be assigned to comb in src/librt/comb/comb.c line 283, right?
probably
I.e., not NULL.
umm yeah
comb = (struct rt_comb_internal *) 0xb03a50
(from gdb)
print comb->magic
still okay?
yea
same as before, 1131375945
Then, RT_CK_COMB(comb);
should be okay too?
(the next line in the source code)
cant check that from gdb, i think
step over the next line (284)
sorry for not replying but something happened and gdb is giving me SIGSEGV in another area
so i will be right back after fixing it
so i fixed it
Daniel Rossberg said:
Then,
RT_CK_COMB(comb);
should be okay too?
it is actually alright, it think
i couldnt step over to 284
hey @Daniel Rossberg , if you come online ping me
i need your help to find out why the segfault is happening
hey @Daniel Rossberg does what should bn_mat_is_identity return
?
Sumagna Das said:
hey Daniel Rossberg does what should bn_mat_is_identity return
grammatical mistake: what should bn_mat_is_identity return?
new backtrace
#0 tcache_get (tc_idx=<optimized out>) at malloc.c:2937
#1 __GI___libc_malloc (bytes=13) at malloc.c:3051
#2 0x00007ffff7e59ad8 in _mid_memalign (address=<optimized out>, bytes=13, alignment=<optimized out>) at malloc.c:3277
#3 __posix_memalign (size=13, alignment=<optimized out>, memptr=0x7fffffffc7a0) at malloc.c:5366
#4 __posix_memalign (memptr=0x7fffffffc7a0, alignment=<optimized out>, size=13) at malloc.c:5353
#5 0x00007fffe7733d91 in alloc (type=CALLOC, cnt=1, sz=13, str=0x7fffeac0dc9b "rt_comb_export5 ext_buf")
at /mnt/sda2/github/brlcad/src/libbu/malloc.c:137
#6 0x00007fffe7733ee5 in bu_calloc (nelem=1, elsize=13, str=0x7fffeac0dc9b "rt_comb_export5 ext_buf")
at /mnt/sda2/github/brlcad/src/libbu/malloc.c:174
#7 0x00007fffea877a07 in rt_comb_export5 (ep=0x7fffffffc9d0, ip=0x7fffffffca90, UNUSED_local2mm=1, dbip=0xd75870,
resp=0x7fffeac88f00 <rt_uniresource>) at /mnt/sda2/github/brlcad/src/librt/comb/comb.c:326
#8 0x00007fffea88fd1b in rt_db_cvt_to_external5 (ext=0x7fffffffca30, name=0x7fffeaf8e090 "sph_with_args_region", ip=0x7fffffffca90, conv2mm=1,
dbip=0xd75870, resp=0x7fffeac88f00 <rt_uniresource>, major=1) at /mnt/sda2/github/brlcad/src/librt/db5_io.c:663
#9 0x00007fffeabf013f in wdb_put_internal (wdbp=0xd54aa0, name=0x7fffeaf8e090 "sph_with_args_region", ip=0x7fffffffca90, local2mm=1)
at /mnt/sda2/github/brlcad/src/librt/wdb.c:246
#10 0x00007fffeabf038d in wdb_export (wdbp=0xd54aa0, name=0x7fffeaf8e090 "sph_with_args_region", gp=0xaa9cc0, id=31, local2mm=1)
at /mnt/sda2/github/brlcad/src/librt/wdb.c:293
#11 0x00007ffff7fbeff5 in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
#12 0x00007ffff7fbe40a in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
#13 0x00007ffff752e69c in _ctypes_callproc () from /usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so
#14 0x00007ffff752ec9c in ?? () from /usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so
#15 0x00000000005f2246 in _PyObject_MakeTpCall ()
#16 0x000000000056c70f in _PyEval_EvalFrameDefault ()
#17 0x00000000005654d2 in _PyEval_EvalCodeWithName ()
#18 0x00000000005f1bc5 in _PyFunction_Vectorcall ()
#19 0x0000000000508386 in ?? ()
#20 0x00000000005f0e3e in PyObject_Call ()
#21 0x0000000000568985 in _PyEval_EvalFrameDefault ()
#22 0x00000000005654d2 in _PyEval_EvalCodeWithName ()
#23 0x0000000000507e8f in ?? ()
#24 0x0000000000568404 in _PyEval_EvalFrameDefault ()
#25 0x00000000005654d2 in _PyEval_EvalCodeWithName ()
#26 0x0000000000686d53 in PyEval_EvalCode ()
#27 0x0000000000676101 in ?? ()
#28 0x000000000067617f in ?? ()
#29 0x0000000000676237 in PyRun_FileExFlags ()
#30 0x00000000006782ba in PyRun_SimpleFileExFlags ()
#31 0x00000000006af5ce in Py_RunMain ()
#32 0x00000000006af959 in Py_BytesMain ()
#33 0x00007ffff7de10b3 in __libc_start_main (main=0x4ec640 <main>, argc=2, argv=0x7fffffffdad8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdac8) at ../csu/libc-start.c:308
#34 0x00000000005f69be in _start ()
Sumagna Das said:
hey Daniel Rossberg does what should bn_mat_is_identity return
It's declared in include/bn/mat.h.
I'll run your Python tests by myself, next week.
sure and they are not actually tests but simple demonstrations of what is possible with the interface right now
but take care to change the genwrapper file according to your brlcad installation location
my installation is default and version is dev-7.31.0
Hey @Daniel Rossberg , if you cloned the github repo for python-brlcad before today, then it might not have the recent changes which fix the memcmp problem and has the recent problem i am struggling to fx
@Sumagna Das how does one reproduce the error you're seeing? The backtrace is still indicating that the call to wdb_export() is wrong. As this is happening on the FFI side of things for ctypesgen, it may be a sign there's something wrong in the binding setup. That said, the crash deep inside malloc typically indicates general corruption too. It might help to run inside valgrind to catch the memory fault earlier.
the malloc error is most recent one which i couldnt fix
Umm I don't know much about the use of valgrind so a little help will be good for me
so i tried using valgrind but cant understand much of it
if you guys can get anything out of it please notify me
this is the log
hey @Daniel Rossberg , what should the shaderargs argument get in this function? https://brlcad.org/docs/doxygen-r64112/db/d4a/group__wdb.xhtml#ga67ddf35d1fcfc8399d90bb8b527700bf
grep says, that shaderargs is usually empty (NULL or ""), but only for shadername "light" "shadows=1" is a good value.
Daniel Rossberg said:
grep says, that shaderargs is usually empty (NULL or ""), but only for shadername "light" "shadows=1" is a good value.
thanks
i might try using mk_region1 for making regions if thats what it is supposed to do
and i also want to know...
why is the function called mk_region1 and not mk_region(i know there is a full caps MK_REGION definition)
Daniel Rossberg said:
grep says, that shaderargs is usually empty (NULL or ""), but only for shadername "light" "shadows=1" is a good value.
i also forgot to ask another thing. what is the membname supposed to be?
or what should be an ideal call to this function
Sumagna Das said:
i also forgot to ask another thing. what is the membname supposed to be?
It's the name of the object you want to put in the region. E.g., the name of an arb8.
The "1" means that you create a region with only one member. There is a mk_comb1() too.
Daniel Rossberg said:
Sumagna Das said:
i also forgot to ask another thing. what is the membname supposed to be?
It's the name of the object you want to put in the region. E.g., the name of an arb8.
The "1" means that you create a region with only one member. There is a mk_comb1() too.
by the object u mean the name of the shape
i have a sph object named 'sphere' and i passed the shader "plastic {di .9 sp .4}"
so should the call to function be like mk_region1(h.db_fp, "random", "sphere", "plastic {di .9 sp .4}", ""/None, "255 0 0") where arguments are fp=h.db_fp, combname="random", membname="sphere", shadername="plastic {di .9 sp .4}", shaderargs=("" or None), rgb="255 0 0"(i dont know much about the rgb argument)
The rgb is not a real string but a 3 byte value with the colors. I.e. a unsigned char rgb[3]
with the numbers for red, green, and blue between 0 and 255.
ohh
can that be a reason for it returning a zero?
i was passing a string and not an array of unsigned char
@Daniel Rossberg, so that might be the reason for the mk_region1 returning 0 when i called it with the above arguments
the previous lines show what the arguments i am passing
You can try to pass 0 (NULL), which means "no color", for now.
Sumagna Das said:
why is the function called mk_region1 and not mk_region(i know there is a full caps MK_REGION definition)
This predates me, but it's quite likely that either (A) there was an mk_region for v4 databases that got replaced when we moved to v5 format (late 90's) or (B) it was to avoid confusion with MK_REGION, particularly for 3rd party devs working in case-insensitive languages like FORTRAN (which was a thing long ago). We should rename it (heck the entire "mk_" prefix is inconsistent and clumsy), and likely will when libg comes to life.
or what daniel said, makes even more sense.. I forgot all about mk_comb1! hah.
Daniel Rossberg said:
You can try to pass 0 (NULL), which means "no color", for now.
passed NULL but nothing new
still gives me 0 for some reason
@Sumagna Das To clarify, are you saying the return code from mk_region1 is a zero and you're wondering why?
I believe a zero return code indicates success...
mk_region1 returns what mk_comb returns which returns what wdb_put_internal returns which returns what wdb_export_external returns which returns zero on success, or non-zero on failure anywhere along that call stack.
oh
i went with the boolean true-false(0=false, 1=true)
btw shouldnt the color of the region show up during raytracing?
understandable. always good to check the header and/or implementation. it's not typical for C functions that have a plethora of potential error conditions to return just zero for all of them unless there's some sort of error argument or a separate error function that will tell you which occurred.
(deleted)
Sumagna Das said:
btw shouldnt the color of the region show up during raytracing?
it depends how the color was set and what you're drawing, but in general yes it should i you set one. that's pretty easy to sort out by looking at the resulting geometry.
so coming to the next issue
what should be passed to mk_comb() to make a region?
i have had no luck with mk_region1()
what does your mk_region1 call look like?
Sumagna Das said:
this is from the python interactive shell
yes, and? :)
and?
do you know how the python code is transforming the wdb.mk_region1 into the actual function call?
i thought it calls the C function directly from this
okay
do you know that j.db_fp.contents is right or should that be j.db_fp?
i think it is
Sean said:
okay
do you know that j.db_fp.contents is right or should that be j.db_fp?
j.db_fp actually
it produces the same when called with j.db_fp
what does it produce?
also, huge different between those two -- need to know which was right
i wanted to mean it returns the same
0
btw should i move the dev-7.31.0-disabled folder back
uhm, I'm not sure the return value has any meaning yet
you should be checking the actual result
the database needs to be closed, and then see if it made a "random" object
Sumagna Das said:
btw should i move the dev-7.31.0-disabled folder back
doesn't matter -- you don't need to install if you're not going to be running from there. if you are going to run from there, you need to consistently run "make install" or you'll end up needing to debug weird states where what's in the install location doesn't match what's in the build tree
having both a build tree specified to compile into /usr/brlcad/dev-7.31.0 and ALSO a previous dev version installed in that same location is just asking for trouble.
if you're not going to use it, you can just delete it or leave it disabled.
i needed the libraries from the lib folder
ah, for linking against ctypesgen?
sure
and i dont want to change every line containing the wrong path in the raw bindings
so yeah, you can move it back -- just keep in mind that if you run into something weird with mged again, first thing to check will be making sure you "make install"'d
region is not there
how was the database closed?
i called the function just now and checked if the region was there
which function?
from mged
i checked from mged
wdb.wdb_close(self.db_fp)
to close the database
there's no python binding in mged that will close the j.db_ip you were using
how is j.db_ip different from self.db_fp ?
and where did .contents come from? really need to know which is correct.
db_ip is the db_i pointer
db_fp is the rt_wdb pointer
I meant j.db_fp and self.db_fp
the .contents is the main variable(not the pointer form)
are there any other mk_ calls that work? what do they look like?
the fucntion call in the picture i referenced was when i was still seeing if it works
mk_sph?
what's a call to it look like?
just like they are normally called from c code
the functions are called the same way in python as they are called in C
the arguments are same
it differs in the language they are called from
>>> wdb.mk_comb()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: this function takes at least 14 arguments (0 given)
the mk_comb requires (as it seems) 14 arguments from python
so what should a mk_comb call look like for a region in C?
mk_region1 just calls mk_comb, so if you can't get region working, you're less likely to get comb working ;)
mk_comb is fully generalized (hence the 14 arguments...)
can you show me a call to mk_sph that works?
yea wait
wdb.mk_sph(self.db_fp, name, point_t(*center), radius)
where radius
is 1 by default (if no arguments are provided), center
is a tuple (0, 0, 0) if no arguments are provided and name
is the name of the sph to be made
btw you might find this call in the Database class in the repo
okay, so then your region call should be something like wdb.mk_region1(self.db_fp, combname, membname, "", "", rgb).
I suspect the issue is passing None for NULL (my quick reading indicates that's not how ctypesgen works). There's also a question of what 'h' was as it looked like in your code that you were supposed to pass 'rgb' (or maybe wants it as a byte array).
h = rgb
rgb was a more generalized name of the variable
sure, but I mean it might need to be in a different format like bytes(rgb)
you'd have to know more intimately what ctypesgen does with a int[3], because the function is expecting a char[3] and will have no way to know how to convert.
i am passing an unsigned char, which is interpreted as c_ubyte in ctypes.
Sean said:
okay, so then your region call should be something like wdb.mk_region1(self.db_fp, combname, membname, "", "", rgb).
I suspect the issue is passing None for NULL (my quick reading indicates that's not how ctypesgen works). There's also a question of what 'h' was as it looked like in your code that you were supposed to pass 'rgb' (or maybe wants it as a byte array).
passing None might be the issue
i tried calling the way you said but it just doesnt work
Sumagna Das said:
i am passing an unsigned char, which is interpreted as c_ubyte in ctypes.
The parameter to mk_region1 doesn't take an unsigned char... it takes a pointer to one. i.e., an array of three unsigned chars.
Unless you meant c_ubyte* that could also be the issue. Can you step through it in a debugger? That will say for certain what is going on and whether the arguments are correct. Just put a breakpoint on mk_region1.
Do you know how to do that?
Sean said:
Unless you meant c_ubyte* that could also be the issue. Can you step through it in a debugger? That will say for certain what is going on and whether the arguments are correct. Just put a breakpoint on mk_region1.
i actually meant c_ubyte *. Sorry for the confusion
hey @Sean , I was thinking about switching the bindings generator to this one https://github.com/gjcarneiro/pybindgen
the ctypesgen one is having some minor problems
so should i try switching to this one?
@Sumagna Das If you feel it's worth trying, sure go for it. You're already way further with ctypesgen than I thought possible.
Did you try running in a debugger to see what was wrong with mk_region1?
Sean said:
Sumagna Das If you feel it's worth trying, sure go for it. You're already way further with ctypesgen than I thought possible.
Did you try running in a debugger to see what was wrong with mk_region1?
i set a breakpoint but it doesnt touch that in gdb
it shows pending but never touches that
what about mk_comb?
what did you set the breakpoint on?
first on the rgb[0] = 153
(the previous line), then on mk_region1
call
if it doesn't break on mk_region1, then you're either crashing/failing before it gets to libwdb or you're not using the debugger in a way that it'll break properly.
how did you set a breakpoint on the python line??
what debugger are you using?
b trial.py:7
and gdb
it not crashing or else gdb wouldnt have reported [Inferior 1 (process 19575) exited normally]
did you try a simple "b mk_region1" ?
or did you use the line number?
line number
try using the symbol instead
should also be able to set a breakpoint on something simple to confirm it's breaking properly like mk_sph or wdb_fopen
symbol?
"b mk_region1" tells gdb to break when it encounters the mk_region1 symbol
whenever and however it is encountered
hmmm
as it seems...
gdb (or python) cannot access shaderargs and rgb
so it stopped in mk_region1?
yea
#0 mk_region1 (wdbp=0x7ffff7fbde79, combname=0x8 <error: Cannot access memory at address 0x8>, membname=0x7fffffffd160 "\001",
shadername=0x7ffff3158c98 "x\331>\367\377\177", shaderargs=0x1 <error: Cannot access memory at address 0x1>,
rgb=0xf <error: Cannot access memory at address 0xf>) at /mnt/sda2/github/brlcad/src/libwdb/reg.c:373
cool, looks like all the args are invalid, not just shaderargs and rgb. and their values are a telling indication of something else wrong.
combname is x8
that's wrong
x8?
combname=0x8
it should be a pointer to a string. it's the number 8
wdb.mk_region1(h.db_fp, 'random', 'comb0', "", "", rgb)
same with shaderargs being '1' and rgb being 15
this is the call from my python script
right, it should be a pointer to "random" but instead it's the value 8
is my call wrong?
given the other examples, that seems unlikely. either memory is simply corrupted due to something else wrong or the ctypesgen mapping isn't set up right or ... it's something we're not yet seeing.
how familiar are you with gdb? print the whole stack trace, go up and see where the vars are coming from
yea wait
i went up where the vars are coming from and supposedly the variables are divided into two dicts i.e., globals
and locals
ima need a paste or screenshot to help understand
#0 mk_region1 (wdbp=0x7ffff7fbde79, combname=0x8 <error: Cannot access memory at address 0x8>, membname=0x7fffffffd160 "\001",
shadername=0x7ffff3158c98 "x\331>\367\377\177", shaderargs=0x1 <error: Cannot access memory at address 0x1>,
rgb=0xf <error: Cannot access memory at address 0xf>) at /mnt/sda2/github/brlcad/src/libwdb/reg.c:373
#1 0x00007ffff7fbeff5 in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
#2 0x00007ffff7fbe40a in ?? () from /lib/x86_64-linux-gnu/libffi.so.7
#3 0x00007ffff752e69c in _call_function_pointer (argcount=6, resmem=0x7fffffffd320, restype=<optimized out>, atypes=0x7fffffffd2a0,
avalues=0x7fffffffd2e0, pProc=0x7ffff34cfea8 <mk_region1>, flags=<optimized out>) at ./Modules/_ctypes/callproc.c:871
#4 _ctypes_callproc (pProc=<optimized out>, argtuple=<optimized out>, flags=<optimized out>, argtypes=<optimized out>, restype=<optimized out>,
checker=<optimized out>) at ./Modules/_ctypes/callproc.c:1199
#5 0x00007ffff752ec9c in PyCFuncPtr_call (self=<optimized out>, inargs=<optimized out>, kwds=0x0) at ./Modules/_ctypes/_ctypes.c:4201
#6 0x00000000005f2246 in _PyObject_MakeTpCall (callable=<_FuncPtr(__name__='mk_region1') at remote 0x7ffff2934700>, args=<optimized out>,
nargs=<optimized out>, keywords=<optimized out>) at ../Include/internal/pycore_pyerrors.h:13
#7 0x000000000056c70f in _PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff75837b8,
callable=<_FuncPtr(__name__='mk_region1') at remote 0x7ffff2934700>) at ../Include/cpython/abstract.h:125
#8 _PyObject_Vectorcall (kwnames=0x0, nargsf=<optimized out>, args=0x7ffff75837b8,
callable=<_FuncPtr(__name__='mk_region1') at remote 0x7ffff2934700>) at ../Include/cpython/abstract.h:115
#9 call_function (kwnames=0x0, oparg=<optimized out>, pp_stack=<synthetic pointer>, tstate=0x95a220) at ../Python/ceval.c:4987
#10 _PyEval_EvalFrameDefault (f=<optimized out>, throwflag=<optimized out>) at ../Python/ceval.c:3469
#11 0x00000000005654d2 in PyEval_EvalFrameEx (throwflag=0, f=Frame 0x7ffff7583640, for file trial.py, line 9, in <module> ())
at ../Python/ceval.c:741
#12 _PyEval_EvalCodeWithName (_co=<optimized out>, globals=<optimized out>, locals=<optimized out>, args=<optimized out>, argcount=<optimized out>,
kwnames=<optimized out>, kwargs=0x0, kwcount=<optimized out>, kwstep=2, defs=0x0, defcount=0, kwdefs=0x0, closure=0x0, name=0x0, qualname=0x0)
at ../Python/ceval.c:4298
#13 0x0000000000686d53 in PyEval_EvalCodeEx (closure=0x0, kwdefs=0x0, defcount=0, defs=0x0, kwcount=0, kws=0x0, argcount=0, args=0x0,
locals=<optimized out>, globals=<optimized out>, _co=<optimized out>) at ../Python/ceval.c:4327
#14 PyEval_EvalCode (co=<optimized out>, globals=<optimized out>, locals=<optimized out>) at ../Python/ceval.c:718
#15 0x0000000000676101 in run_eval_code_obj (co=0x7ffff753ff50,
globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='trial.py') at remote 0x7ffff75446d0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff760d0e0>, '__file__': 'trial.py', '__cached__': None, 'Database': <_ctypes.PyCStructType at remote 0x108ed60>, 'wdb': <module at remote 0x7ffff7498860>, 'pdb': <module at remote 0x7ffff7498680>, 'h': <Database(db_ip=<LP_struct_db_i at remote 0x7fffe65f6940>, db_fp=<LP_struct_rt_wdb at remote 0x7fffe65f62c0>) at remote 0x7fffe65f6840>, 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>},
locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='trial.py') at remote 0x7ffff75446d0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff760d0e0>, '__file__': 'trial.py', '__cached__': None, 'Database': <_ctypes.PyCStructType at remote 0x108ed60>, 'wdb': <module at remote 0x7ffff7498860>, 'pdb': <module at remote 0x7ffff7498680>, 'h': <--Type <RET> for more, q to quit, c to continue without paging--c
Database(db_ip=<LP_struct_db_i at remote 0x7fffe65f6940>, db_fp=<LP_struct_rt_wdb at remote 0x7fffe65f62c0>) at remote 0x7fffe65f6840>, 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>}) at ../Python/pythonrun.c:1125
#16 0x000000000067617f in run_mod (mod=<optimized out>, filename=<optimized out>, globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='trial.py') at remote 0x7ffff75446d0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff760d0e0>, '__file__': 'trial.py', '__cached__': None, 'Database': <_ctypes.PyCStructType at remote 0x108ed60>, 'wdb': <module at remote 0x7ffff7498860>, 'pdb': <module at remote 0x7ffff7498680>, 'h': <Database(db_ip=<LP_struct_db_i at remote 0x7fffe65f6940>, db_fp=<LP_struct_rt_wdb at remote 0x7fffe65f62c0>) at remote 0x7fffe65f6840>, 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>}, locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='trial.py') at remote 0x7ffff75446d0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff760d0e0>, '__file__': 'trial.py', '__cached__': None, 'Database': <_ctypes.PyCStructType at remote 0x108ed60>, 'wdb': <module at remote 0x7ffff7498860>, 'pdb': <module at remote 0x7ffff7498680>, 'h': <Database(db_ip=<LP_struct_db_i at remote 0x7fffe65f6940>, db_fp=<LP_struct_rt_wdb at remote 0x7fffe65f62c0>) at remote 0x7fffe65f6840>, 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>}, flags=<optimized out>, arena=<optimized out>) at ../Python/pythonrun.c:1147
#17 0x0000000000676237 in PyRun_FileExFlags (fp=0x95a9b0, filename_str=<optimized out>, start=<optimized out>, globals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='trial.py') at remote 0x7ffff75446d0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff760d0e0>, '__file__': 'trial.py', '__cached__': None, 'Database': <_ctypes.PyCStructType at remote 0x108ed60>, 'wdb': <module at remote 0x7ffff7498860>, 'pdb': <module at remote 0x7ffff7498680>, 'h': <Database(db_ip=<LP_struct_db_i at remote 0x7fffe65f6940>, db_fp=<LP_struct_rt_wdb at remote 0x7fffe65f62c0>) at remote 0x7fffe65f6840>, 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>}, locals={'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <SourceFileLoader(name='__main__', path='trial.py') at remote 0x7ffff75446d0>, '__spec__': None, '__annotations__': {}, '__builtins__': <module at remote 0x7ffff760d0e0>, '__file__': 'trial.py', '__cached__': None, 'Database': <_ctypes.PyCStructType at remote 0x108ed60>, 'wdb': <module at remote 0x7ffff7498860>, 'pdb': <module at remote 0x7ffff7498680>, 'h': <Database(db_ip=<LP_struct_db_i at remote 0x7fffe65f6940>, db_fp=<LP_struct_rt_wdb at remote 0x7fffe65f62c0>) at remote 0x7fffe65f6840>, 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>}, closeit=1, flags=0x7fffffffd938) at ../Python/pythonrun.c:1063
#18 0x00000000006782ba in PyRun_SimpleFileExFlags (fp=0x95a9b0, filename=<optimized out>, closeit=1, flags=0x7fffffffd938) at ../Python/pythonrun.c:428
#19 0x00000000006af5ce in pymain_run_file (cf=0x7fffffffd938, config=0x95ad90) at ../Modules/main.c:381
#20 pymain_run_python (exitcode=0x7fffffffd930) at ../Modules/main.c:565
#21 Py_RunMain () at ../Modules/main.c:644
#22 0x00000000006af959 in Py_BytesMain (argc=<optimized out>, argv=<optimized out>) at ../Modules/main.c:698
#23 0x00007ffff7de10b3 in __libc_start_main (main=0x4ec640 <main>, argc=2, argv=0x7fffffffdb18, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffdb08) at ../csu/libc-start.c:308
#24 0x00000000005f69be in _start () at ../Objects/obmalloc.c:1233
cool, so looks like it's definitely getting called through ctypes, doing a FFI function lookup to call mk_region1
from the look of it, I would guess is that the ctypes marshalling is wrong which mean ctypesgen isn't specified correctly or it's parsing something incorrectly
you could try going up to frame #3, to _call_function_pointer, and inspect atypes and avalues ... those presumably are the arguments. confirm that the first argument is the right type. it should be a c_char_p, however that get encoded in atypes
atypes
= (ffi_type **) 0x7fffffffd2a0
avalues
= (void **) 0x7fffffffd2e0
there's nothing much in those two variables
The globals
and locals
in one of the frames are the variables I am using to call mk_region1
Probably in frame 17
Sumagna Das said:
The
globals
andlocals
in one of the frames are the variables I am using to call mk_region1
the main thing here is that i cant check from them
like this one 'rgb': <c_ubyte_Array_3 at remote 0x7fffe65f68c0>}
it says at remote 0x7fffe65f68c0
Sumagna Das said:
there's nothing much in those two variables
everything is in those two variables :grinning:
it's just typewise, they are opaque. you have to lok at atypes to get the ffi type, then one can cast the a_values pointer to the right type from void*
Sean said:
Sumagna Das said:
there's nothing much in those two variables
everything is in those two variables :grinning:
it's just typewise, they are opaque. you have to look at atypes to get the ffi type, then one can cast the a_values pointer to the right type from void*
i mean i dont know which type it is and which type to cast avalues to so that i can get what it contains
if you read atypes[0] or *atypes[0], that should give an ffi type directly or a code that implies a type indirectly.
then you cast avalues[0] or *avalues[0] to whatever that type is, probably. maybe a field of *avalues[0], depends what you see.
i have to see to that later
I wish there was a way I could attach to your debugger remotely!
@Sumagna Das do you have a .bz account? you could try setting up and running on our server and I could see what's going on there.
Sean said:
Sumagna Das do you have a .bz account? you could try setting up and running on our server and I could see what's going on there.
will do that if u want
and also where should i signup?
will follow up with private messages
ok
hey @Sean, i setted up python-brlcad on the server. i didnt have time before today....
you can see now what it says
i changed the bindings generator from ctypesgen
to pybindgen
.
i am going to try it out and see if it works.
the ctypesgen was not working out for me
@Sean if it works, i will tell you else it will be dead as before
one of the main problems i have encountered till now is that the lib path has to be in the LD_LIBRARY_PATH
variable if on linux
dont know the same for windows
it still doesnt get all the functions :sad: :cry: :sweat:
Last updated: Jan 09 2025 at 00:46 UTC