nakijun / zengl

Automatically exported from code.google.com/p/zengl
0 stars 0 forks source link

Dynamic arrays in zglChipmunk can be problematic #53

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Some records in zglChipmunk have dynamic arrays. This can be problematic when 
passing these record to the Chipmunk library (or DLL) since Chipmunk does not 
know anything about FreePascal/Delphi dynamic arrays.

For example, the cpPolyShape.verts field is declared as an "array of cpVect". 
It is probably safer to directly translate the Chipmunk header file and use 
"PcpVect" instead.

As long as you don't touch the verts-field, you are probably fine. Because, 
internally a dynamic array is also just a pointer to the first element in the 
array. However, the automatic memory management that comes with dynamic array 
may introduce issues when mixing these with C code in the Chipmunk library.

Original issue reported on code.google.com by bil...@planet.nl on 23 Jan 2012 at 8:44

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
array of something is just a pointer, there is no additional information in it. 
Any kind of such information stores only in memory manager, but only for arrays 
which are created in Pascal-code. Something like that can be noticed for 
Strings. @String[ 1 ] - just a PAnsiChar/PWideChar. And cpPolyShape.verts/etc. 
creates on Chipmunk side, so it always behaves as expected and works just 
fine(tested on every platform).

Original comment by dr.andru@gmail.com on 23 Jan 2012 at 9:35

GoogleCodeExporter commented 9 years ago
OK. Thanks for your comments. I was a bit worried because dynamic arrays also 
store some side information like reference count and array length. But if it 
passes all tests, then it should be good.

Sorry to waste your time on this.

Original comment by bil...@planet.nl on 23 Jan 2012 at 10:36