I’m using a TCPsocket in a callback from an external library and it crashes my app with a “RuntimeLockObject” in the Xojo framework as the last thing on the thread.
This is not being called in anything but the main thread.
Am I doing something wrong here? It crashes even if I try to stop it in the debugger so it’s tough to know how to trouble-shoot this as well…
code?
your callback is to a global method in a module?
Because with a method in a class, the first parameter may not be the instance as expected by Xojo.
Is there a typical convention for associating an instance with such a callback?
Having to use a shared method does a pretty good job of breaking my OOP design. I can think of a few ideas for re-associating the callback with an instance but they all seem like hacks…
Most callback APIs will pass a token to the callback in order to identify the instance that should be notified.
What I do is use this token as the key into a shared dictionary whose values are references (or weakrefs) to instances of the class. In the shared callback method, use the token to lookup the instance in the dictionary, and then call a private method on the instance (shared methods can access private and protected instance members.)
e.g.
[code]
Class MyClass
Private Shared Instances As Dictionary
Private Shared Function MyCallback(Token As Integer) As Integer
' Locate the instance that should be notified of the callback
Dim theinstance As MyClass = Instances.Lookup(Token, Nil)
If theinstance <> Nil Then
Return theinstance.InstanceHandlerMethod() ' call the private handler method on the instance
End If
End Function
Private Sub InstanceHandlerMethod()
' The callback is handled by the instance in this method.
End Sub