[Bf-committers] C++ DLL in blender modifier

Fazekas László mneko at freemail.hu
Mon Jun 13 07:51:36 CEST 2016


Hello Lukas,

To find what is the problem, you should check the calling point and the 
called dll function in assembly. I'm not familiar with Visual Studio but 
I think it's easy to make a disassembled dump of these parts. Maybe you 
can add a breakpoint and then see what happens.

Perhaps the function returns its value in a different register, or on 
the stack, or it has a different integer size (32<->64 bits). When you 
know exactly what is the problem, it's easier to find how to avoid it.

Bests,
Fazek


2016-06-12 22:45 keltezéssel, Lukas Gersthofer írta:
> Hello Henrique,
>
> modifiers in Blender are written in C and are embedded in the source code,
> thus ctypes is not an option, but thanks for your reply!
> To clear things up:
> My modifier calls a function implemented in my DLL which simply takes the
> mesh (vertex positions, face indices) as input, processes it and returns an
> integer result code. But the positions are not changed and the result code
> is random garbage (e.g. -310671472). I guess there's something wrong with
> the call (e.g. wrong calling convention) and therefore the stacks are
> incompatible (parameters and return value get messed up). I compiled the
> library with the same build settings as set in Blender (x64, Release). I am
> using Visual Studio 2013 if that helps.
>
> So I'm still looking for the solution. :-(
>
>
> On Sun, Jun 12, 2016 at 9:44 PM, Henrique Nunes Jung <henriquenj at gmail.com>
> wrote:
>
>> Hello Lukas
>>
>> I have done something related a couple of weeks ago. I didn't implemented a
>> modifier, instead I implemented a RenderEngine. My engine is written in
>> C++, so I created a C wrapper around it and called from Blender using
>> ctypes [1]. I didn't understand how you are calling your C functions, from
>> what I  recall __declspec is just to make your functions available as entry
>> points on the DLL. Anyway I suggest you to take a look at ctypes, because I
>> have successfully use it to call C functions using python from Blender. You
>> can look at my plugin at github[2].
>>
>> Hope it helps
>> Henrique Jung
>>
>> [1] https://docs.python.org/3.5/library/ctypes.html
>> [2] https://github.com/henriquenj/rendergirl/tree/master/BlenderPlugin
>>
>> On 11 June 2016 at 17:08, Lukas Gersthofer <lukasgersthofer at gmail.com>
>> wrote:
>>
>>> Dear Blender Dev community,
>>>
>>> I encountered a problem while implementing a new modifier. The modifier
>>> aims at optimizing the physical properties (center of mass, moments of
>>> inertia, etc.) of a shape. After 3D printing the model is able to stand
>> in
>>> an upright position, rotate around a given axis, etc. (see
>>>
>>>
>> https://www.cg.tuwien.ac.at/research/publications/2015/musialski-2015-souos/musialski-2015-souos-preprint.pdf
>>> )
>>> The implementation of the algorithm is in C++ and I created a DLL which
>> has
>>> a C API as well. Now I wanted to integrate the algorithm into blender as
>> a
>>> modifier. The modifier is almost done but the API call doesn't work
>>> properly. There are no errors but the return values are random bullshit.
>>> The calling convention I use is __declspec.
>>>
>>> If you need further insight into the code, I can share my repository with
>>> you. The algorithm is going to be open source as soon as all features are
>>> implemented and are working properly.
>>>
>>> I would really appreciate a helpful anwer cause I'm really struggling
>> with
>>> this problem and because it is my bachelor thesis I wanted to try
>>> everything to finish it!
>>>
>>> --
>>> mit freundlichen Grüßen / with kind regards
>>>
>>> Lukas Gersthofer
>>> Vienna University of Technology
>>> _______________________________________________
>>> Bf-committers mailing list
>>> Bf-committers at blender.org
>>> https://lists.blender.org/mailman/listinfo/bf-committers
>>>
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> https://lists.blender.org/mailman/listinfo/bf-committers
>>
>
>



More information about the Bf-committers mailing list