Lets see if I can explain this, it took me all night to get grips of what is going on.
First of I have several times in the past removed Module name space from plugins because of issues that I have not been able to explain. And then on others things have seemed fine, but probably are not fine.
Lets consider this Module and Class here:
EinhugurMacOSBridge.NSImage
This is put on push button:
[i]Sub Action() Handles Action
Dim image as EinhugurMacOSBridge.NSImage
image = EinhugurMacOSBridge.NSImage.FromFileType(“txt”)
End Sub[/i]
We crash…
It took me long while to figure out why we are crashing there. Since I had other projects that seemed just like that using same class and no issue.
Crash happens because:
REALclassRef ref = REALGetClassRef(“EinhugurMacOSBridge.NSImage”); // Returns NULL
REALobject instance = REALnewInstanceWithClass(ref); // Returns NULL (because ref was NULL)
In same way this one will also return NULL:
REALobject instance = REALnewInstanceOfClass(&NSImageClass); // Returns NULL.
At this point I did not know what to think since I have same thing working in other projects using same class:
Few hours later I had nailed it…
If I add property to the Window1 in the Xojo project like: dummy as EinhugurMacOSBridge.NSImage
then situation becomes this:
REALclassRef ref = REALGetClassRef(“EinhugurMacOSBridge.NSImage”); // Returns valid reference
REALobject instance = REALnewInstanceWithClass(ref); // Returns valid object
REALobject instance = REALnewInstanceOfClass(&NSImageClass); // Returns valid object.
And of course finally removing the Module namespace then it works always without adding dummy property to the Window1 in the project.