realbasic-nug
[Top] [All Lists]

Re: Delegate.Invoke and memoryBlock/nil/ptr conversions?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Delegate.Invoke and memoryBlock/nil/ptr conversions?
From: Michael Diehr <md03@xochi.com>
Date: Fri, 29 May 2009 10:41:18 -0700
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <9A86B21A-D9C1-4737-AD6F-9D45C3363F1F@declareSub.com>
References: <DA25CAB7-E9AC-4C64-B758-46948A20273D@xochi.com> <FFA512D9-E586-498A-A799-7BA8E875D0F5@declareSub.com> <776FCB16-0B35-4A67-967B-9F1481B9B2DE@xochi.com> <9A86B21A-D9C1-4737-AD6F-9D45C3363F1F@declareSub.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Ok -- so the logic here is that when a method is expecting a Ptr, and you pass it a nil memoryblock, it is the operator_convert that is raising the exception? It almost seems like operator_convert should be smarter when dealing with nil objects?

Or, perhaps a IllegalCastException would make more sense?

It would not, because you're not casting in this situation; you are converting. The conversion is accomplished by invoking a method; when the object reference is nil, a NilObjectException is the correct exception type.

But I cannot reproduce your situation...

You can see this technique useed in the rgbl code:

Private Delegate Function wglChoosePixelFormatARBDelegate(hdc as UInt32, piAttribIList as Ptr, piAttribFList as Ptr, nMaxFormats as UInt32, byref piFormats as UInt32, byref nNumFormats as UInt32) As Integer

[...]

    //get pointer to pbuffer create function
declare function wglGetProcAddress lib GL_LIB (lpszProc as CString) as Ptr
    dim fnPtr as Ptr = wglGetProcAddress("wglChoosePixelFormatARB")

    //choose pixel format
    dim pixelFormat as uint32
    if fnPtr <> nil then
      dim null as ptr
      dim count as uint32 = 0
      dim fn as new wglChoosePixelFormatARBDelegate(fnPtr)
      call fn.Invoke(current_hdc, attribs, null, 1, pixelFormat, count)
      if count = 0 then
raise new RBGLException("could not find a suitable pixel format for the pbuffer")
      end
    else
raise new RBGLException("wglChoosePixelFormatARB is not supported on this system")
    end



As you see, they are intentionally passing "null" (a nil Ptr) instead of nil to the delegate function that is expecting a Ptr. If you try to pass nil, then it fails.




_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>