[MacRuby-devel] Pointer to memory. was: Pointers for BOOL types
John Shea
johnmacshea at gmail.com
Fri Jan 9 22:47:12 PST 2009
Hi Brian,
thanks for your comment.
Strangely enough that's what I did by accident the first time.
It actually seems a bit dodgy (at least to my way of thinking) - that
not only are the objects of my method parameter list changing, but
that the repository of my data if nil will dictate a different
behaviour in the method.
I am not a no-side-effect bigot guy, but I can think of clearer ways
to structure methods.
So it then took me a while to figure out why my program was not
working because i kept thinking - "but my data is just waiting to be
filled - I set it to nil!" - and in fact post method, the "data"
reference was still pointing to nil. (There were a lot of more obvious
things that could be wrong, that i went through first - and having
cycled through three different Apple graphics technologies already ...)
I actually need this data pointer to pop into an opengl call.
Trying to reference it by : data = CGBitmapContextGetData(context)
does not work. and:
data = Pointer.new_with_type('^v')
#data = CGBitmapContextGetData(context)
data.assign(CGBitmapContextGetData(context))
does not work either (although at least it does not crash - so the
type seems to be correct - the pointer is just not pointing to the
correct bitmap and garbage is sent to the opengl method).
data = CGBitmapContextGetData(context) will work for me if i create
the context (and malloc the data ref) in objective c and return the
context.
Thats my workaround and it works fine.
Cheers,
John.
On Jan 9, 2009, at 11:57 PM, Brian Chapados wrote:
> If it helps, for CGBitmapContextCreate you just pass NULL ('nil' in
> MacRuby) for the void *data parameter and let CoreGraphics handle
> allocating memory. Unless you really need to do the allocation
> yourself, it is significantly less painful and less error-prone to
> have it done automatically, especially if you're using CoreGraphics
> from MacRuby.
>
> Brian
>
> On Fri, Jan 9, 2009 at 12:00 AM, John Shea <johnmacshea at gmail.com>
> wrote:
>> Thanks for the pointer ( ;-)) Dave,
>> I assume that there is some way to make it work since it seems, as
>> you say,
>> to be catered for, but with my code it either gives back garbage
>> (ie not a
>> pointer to the image i want) or falls into the debugger depending
>> on whether
>> i access it more than once.
>> Never mind, I have a work-around that works fine - it was easy to
>> call out
>> to an Objective C method where I could create the pointer in the C
>> way (void
>> *data = malloc(width * height * 4);).
>> Cheers,
>> John
>>
>>
>> On Thu, Jan 8, 2009 at 6:45 PM, Dave Lee <davelee.com at gmail.com>
>> wrote:
>>>
>>> try "^v". ^ is pointer, v is void.
>>>
>>> If you look at the .bridgesupport file, in this case
>>>
>>> /System/Library/Frameworks/ApplicationServices.framework/
>>> Frameworks/CoreGraphics.framework/Resources/BridgeSupport/
>>> CoreGraphicsFull.bridgesupport,
>>> you'll see the the objc types listed for the various functions,
>>> structs, etc.
>>>
>>> Dave
>>>
>>> On Sat, Jan 3, 2009 at 12:28 AM, John Shea <johnmacshea at gmail.com>
>>> wrote:
>>>> So kind of on this topic ..
>>>> which one of these ("c", "i", "s" etc) do I use for void pointers
>>>> (to
>>>> memory) eg. the data parameter in the method below? (when otherwise
>>>> appropriately changed to ruby and Application.services imported
>>>> etc).
>>>>
>>>> CGContextRef CGBitmapContextCreate (
>>>> void *data,
>>>> size_t width,
>>>> size_t height,
>>>> size_t bitsPerComponent,
>>>> size_t bytesPerRow,
>>>> CGColorSpaceRef colorspace,
>>>> CGBitmapInfo bitmapInfo
>>>> );
>>>>
>>>> Cheers,
>>>>
>>>> J
>>>>
>>>> On Jan 2, 2009, at 11:21 PM, Dave Lee wrote:
>>>>
>>>> On Thu, Jan 1, 2009 at 7:37 PM, Lachie <lachiec at gmail.com> wrote:
>>>>
>>>> Cheque it:
>>>>
>>>> http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/chapter_7_section_1.html#/
>>>> /apple_ref/doc/uid/TP40008048-CH100-SW1
>>>>
>>>> see also: /usr/include/objc/runtime.h
>>>>
>>>> Dave
>>>> _______________________________________________
>>>> MacRuby-devel mailing list
>>>> MacRuby-devel at lists.macosforge.org
>>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>>
>>>>
>>>> _______________________________________________
>>>> MacRuby-devel mailing list
>>>> MacRuby-devel at lists.macosforge.org
>>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>>>
>>>>
>>> _______________________________________________
>>> MacRuby-devel mailing list
>>> MacRuby-devel at lists.macosforge.org
>>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>>
>> _______________________________________________
>> MacRuby-devel mailing list
>> MacRuby-devel at lists.macosforge.org
>> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>>
>>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20090110/c42acc08/attachment-0001.html>
More information about the MacRuby-devel
mailing list