realbasic-plugins
[Top] [All Lists]

Treating a class as a control... bummer?

To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot com>
Subject: Treating a class as a control... bummer?
From: Alfred Van Hoek <vanhoek at mac dot com>
Date: Sun, 24 Apr 2005 14:34:48 -0400
Delivered-to: realbasic-plugins at lists dot realsoftware dot com
Stunned by the following finding. When a class defines a struct like:

typedef struct MyData {
    REALobject    self;
    REALobject    styledText;
    REALobject    Features;
    REALobject    AnotherObject;
    REALobject    Object;
    
    ..
} MyData;

the object at position 4 "AnotherObject" is behaving strange, when and only
when the class is dropped on the window. The complete struct contains 428
bytes and the default constructor sets these objects to nil, apart from
self, which represents the class instance.

When window1 contains the instance MyData1 and multiple windows of window1
are created and then closed again, the destructor will call UnlockObject on
these objects (but not on "self" of course). These objects though are nil,
they were not modified at all, but every time an instance of window1 is
destructed, by closing the window, "AnotherObject" appears to be not nil.
REALUnlockObject is executed on this nil object, at after the fourteenth
window is closed, the app crashes and the log tells that it crashed in
REALUnlockObject (As it should have done so already when a first window was
closed).

When "AnotherObject" is exchanged with "Object" like:

    REALobject    self;
    REALobject    styledText;
    REALobject    Features;
    REALobject    Object;
    REALobject    AnotherObject;

"Object" appears to be non nil, clearly demonstrating that something is
happening beyond plugin code when a class instance is put onto the window,
when the user is treating MyClass as a control.

When MyClass is instantiated in code (not being treated as a rectControl),
all objects in the struct, apart from self remain nil.

RS: is there something special that treats bytes 16-20 different from other
offsets in the class' struct?

The workaround seems to be to add a "FakeField" in the class' struct, but am
not so happy with this finding. I don't believe the plugin is clobbering
memory though, and will try to provide a sample plug to make sure the plugin
is not affecting memory and convince that something is really wrong with
RB's ability to create a rectControl from a class. For example, it does not
preserve preset property values carried out in the class constructor
either...

Alfred


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

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

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