Xojo Conferences
MBSOct2019CologneDE

Plugin crashes... need help (Real Studio Plugins Mailinglist archive)

Back to the thread list
Next thread: nilObjectException Why


macosx and unix paths   -   GOLD
  Plugin crashes... need help   -   Phil M
   Re: Plugin crashes... need help   -   Theodore H. Smith
   Re: Plugin crashes... need help   -   Phil M
   Re: Plugin crashes... need help   -   Theodore H. Smith
   Re: Plugin crashes... need help   -   Phil M
   Re: Plugin crashes... need help   -   Theodore H. Smith
   Re: Plugin crashes... need help   -   Phil M
   Re: Plugin crashes... need help   -   Theodore H. Smith

Plugin crashes... need help
Date: 25.07.06 20:35 (Tue, 25 Jul 2006 15:35:52 -0400)
From: Phil M
I haven't had the time to work on my plugin until just a few minutes
ago, but I think that I have isolated the crash... well at least I
figured out what it is not.

Contrary to what I thought on Saturday morning, the plugin is not
crashing when I try to create the object. Instead the crash occurs
when I try to access *any* of the methods of the object. It is as if
the object is Nil, but according to REALbasic the object is *not* Nil
("If (obj Is Nil) Then"). The really bizarre thing is that
properties seem to work fine.

The only example that I have for classes is Thomas Tempelmann's
Plugin Starter. In this he uses REALbasic to create the class
structure and then uses a standard "C struct" to contain all of the
data of the class. That is the model that I am following since it
allows me to let REALbasic handle the object creation/destruction.

In every method he has the following call to an unknown (to me)
method called "ClassData()" and uses a variable that I am not
familiar with ("me"). Is this method and variable part of the
REALbasic Plugin SDK? I cannot find any reference to them in the
documentation. Here is an example of one of his methods using this
call:

static void sampleBoolRefGetter (REALobject instance, RBboolPar *value)
// returns a boolean value via a BYREF parameter
{
ClassData (sampleClass, instance, sampleClassData, me);
*value = me->aBoolean;
}

Since this works perfectly for properties, I am really confused as to
why any call to the class methods will crash.

In the crash log, the crash is because of:

-----------------------------------------------------------------
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
0 <<00000000>> 0x00000000 0 + 0
1 rbframework.dylib 0x0028e390 RuntimeMenuItemClick +
868
2 rbframework.dylib 0x0027bc74 AppCarbonEventHandler
(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 316
-----------------------------------------------------------------

Which looks to be like I am trying to access a NULL pointer. Yes, I
am calling my plugin test code from a MenuItem which is how the final
app would be used as well.

In case you need my stats:
- REALbasic 2006 r3 (release)
- REALbasic Plugin SDK packaged with 2006 r3
- CodeWarrior 9.2
- OS X 10.4.7
- Compiling plugin as Carbon with links to "CarbonLib" and
"MSL_C_Carbon.lib"
- Compiling test app in REALbasic as Mach-O to enable full support
for CrashLog

_______________________________________________
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>

Re: Plugin crashes... need help
Date: 25.07.06 21:02 (Tue, 25 Jul 2006 21:02:19 +0100)
From: Theodore H. Smith

On 25 Jul 2006, at 20:35, Phil M wrote:

> I haven't had the time to work on my plugin until just a few
> minutes ago, but I think that I have isolated the crash... well at
> least I figured out what it is not.
>
> Contrary to what I thought on Saturday morning, the plugin is not
> crashing when I try to create the object. Instead the crash occurs
> when I try to access *any* of the methods of the object. It is as
> if the object is Nil, but according to REALbasic the object is
> *not* Nil ("If (obj Is Nil) Then"). The really bizarre thing is
> that properties seem to work fine.
>
> The only example that I have for classes is Thomas Tempelmann's
> Plugin Starter. In this he uses REALbasic to create the class
> structure and then uses a standard "C struct" to contain all of the
> data of the class. That is the model that I am following since it
> allows me to let REALbasic handle the object creation/destruction.
>
> In every method he has the following call to an unknown (to me)
> method called "ClassData()" and uses a variable that I am not
> familiar with ("me"). Is this method and variable part of the
> REALbasic Plugin SDK? I cannot find any reference to them in the
> documentation. Here is an example of one of his methods using this
> call:
>
> static void sampleBoolRefGetter (REALobject instance, RBboolPar
> *value)
> // returns a boolean value via a BYREF parameter
> {
> ClassData (sampleClass, instance, sampleClassData, me);
> *value = me->aBoolean;
> }
>

My guess is ClassData is returning the wrong value. Is everything set
up correct? instance is probably correct, but is sampleClass good, or
sampleClassData?

Try something like:

if (!me) {
REALMessageBox( "argh me=nil" );
}

Except you'll need a function which takes a char*, as REALMessageBox
takes a REALstring.

Can you set breakpoints in your plugin? Or printf stuff to the
console? You must be able to DebugStr stuff to the console... that's
always on OSX.

> Since this works perfectly for properties, I am really confused as
> to why any call to the class methods will crash.
>
> In the crash log, the crash is because of:
>
> -----------------------------------------------------------------
> Exception: EXC_BAD_ACCESS (0x0001)
> Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x00000000
>
> Thread 0 Crashed:
> 0 <<00000000>> 0x00000000 0 + 0
> 1 rbframework.dylib 0x0028e390 RuntimeMenuItemClick
> + 868
> 2 rbframework.dylib 0x0027bc74 AppCarbonEventHandler
> (OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 316
> -----------------------------------------------------------------
>
> Which looks to be like I am trying to access a NULL pointer. Yes,
> I am calling my plugin test code from a MenuItem which is how the
> final app would be used as well.
>
> In case you need my stats:
> - REALbasic 2006 r3 (release)
> - REALbasic Plugin SDK packaged with 2006 r3
> - CodeWarrior 9.2
> - OS X 10.4.7
> - Compiling plugin as Carbon with links to "CarbonLib" and
> "MSL_C_Carbon.lib"
> - Compiling test app in REALbasic as Mach-O to enable full
> support for CrashLog
>
> _______________________________________________
> 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>

Re: Plugin crashes... need help
Date: 25.07.06 21:14 (Tue, 25 Jul 2006 16:14:06 -0400)
From: Phil M
On Jul 25, 2006, at 4:02 PM, Theodore H. Smith wrote:

> My guess is ClassData is returning the wrong value. Is everything
> set up correct? instance is probably correct, but is sampleClass
> good, or sampleClassData?
>
> Try something like:
>
> if (!me) {
> REALMessageBox( "argh me=nil" );
> }
>
> Except you'll need a function which takes a char*, as
> REALMessageBox takes a REALstring.
>
> Can you set breakpoints in your plugin? Or printf stuff to the
> console? You must be able to DebugStr stuff to the console...
> that's always on OSX.

I have not been able to get REALbasic and CodeWarrior to work with
breakpoints. I don't know what I need to do to get that to work, all
break points are just ignored even though I am running in the
CodeWarrior debugger (with auto RB launch).

In regards to logging, yes I have been using a combination of
REALbasic System.DebugLog and DebugStr. In REALbasic a
System.DebugLog msg is right before the call to the method and it
outputs to the Console as expected. In the method, I have a DebugStr
call which is never printed, so the crash seems to be occurring
somewhere in the framework even before my plugin method is getting
called. There doesn't seem to be anything else that I can do to
isolate this.

Like I mentioned before, the properties are working fine. It is just
the methods that are getting all screwy.

_______________________________________________
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>

Re: Plugin crashes... need help
Date: 25.07.06 21:52 (Tue, 25 Jul 2006 21:52:44 +0100)
From: Theodore H. Smith

On 25 Jul 2006, at 21:14, Phil M wrote:

> On Jul 25, 2006, at 4:02 PM, Theodore H. Smith wrote:
>
>> My guess is ClassData is returning the wrong value. Is everything
>> set up correct? instance is probably correct, but is sampleClass
>> good, or sampleClassData?
>>
>> Try something like:
>>
>> if (!me) {
>> REALMessageBox( "argh me=nil" );
>> }
>>
>> Except you'll need a function which takes a char*, as
>> REALMessageBox takes a REALstring.
>>
>> Can you set breakpoints in your plugin? Or printf stuff to the
>> console? You must be able to DebugStr stuff to the console...
>> that's always on OSX.
>
> I have not been able to get REALbasic and CodeWarrior to work with
> breakpoints. I don't know what I need to do to get that to work,
> all break points are just ignored even though I am running in the
> CodeWarrior debugger (with auto RB launch).
>
> In regards to logging, yes I have been using a combination of
> REALbasic System.DebugLog and DebugStr. In REALbasic a
> System.DebugLog msg is right before the call to the method and it
> outputs to the Console as expected. In the method, I have a
> DebugStr call which is never printed,

At the very start of the function?

> so the crash seems to be occurring somewhere in the framework even
> before my plugin method is getting called. There doesn't seem to
> be anything else that I can do to isolate this.

Then perhaps the function is declared wrong.

The fact that you are define the the REALClassDefinitions and all
theo other data in .h files can't help. You should define them in
a .cpp file. This way data doesn't get duplicated across multiple
files that include the .h file.

#include is nothing more than a dumb preprocessor you see. So
anything in a .h file gets put into all the .cpp files that include
it. So you've got the same data defined multiple times now if you
have multiple .cpp files that include that .h of yours. If it's only
1 .cpp it might not be a problem, but I'd really avoid it if I were
you just on good coding practice grounds.

> Like I mentioned before, the properties are working fine. It is
> just the methods that are getting all screwy.

_______________________________________________
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>

Re: Plugin crashes... need help
Date: 26.07.06 00:05 (Tue, 25 Jul 2006 19:05:25 -0400)
From: Phil M
On Jul 25, 2006, at 4:52 PM, Theodore H. Smith wrote:

>> In regards to logging, yes I have been using a combination of
>> REALbasic System.DebugLog and DebugStr. In REALbasic a
>> System.DebugLog msg is right before the call to the method and it
>> outputs to the Console as expected. In the method, I have a
>> DebugStr call which is never printed,
>
> At the very start of the function?

Yes. The app crashes before the DebugStr from the C plugin. It
crashes here:

If (ImageFX Is Nil) Then ImageFX = New PictureFX(Image)
System.DebugLog "PictureFX object created."
If (ImageFX Is Nil) Then System.DebugLog "ImageFX is Nil"

System.DebugLog "Picture Width is " + Str(ImageFX.Width)
System.DebugLog "Picture Height is " + Str(ImageFX.Height)
System.DebugLog "Picture Depth is " + Str(ImageFX.Depth)

ImageFX.InvertRGB <<<<<<<<<<<<<<<<<<< CRASH ON CALL
System.DebugLog "InvertRGB completed."

Image = ImageFX.ToPicture
System.DebugLog "PictureFX to Picture conversion completed."

--------------------
CONSOLE OUTPUT:
--------------------

PictureFX object created.
Picture Width is 512
Picture Height is 512
Picture Depth is 32
Jul 25 18:52:45 ag4 crashdump[13015]: TestApp.debug crashed

>> so the crash seems to be occurring somewhere in the framework even
>> before my plugin method is getting called. There doesn't seem to
>> be anything else that I can do to isolate this.
>
> Then perhaps the function is declared wrong.

I hope so, but I cannot figure out how.

> The fact that you are define the the REALClassDefinitions and all
> theo other data in .h files can't help. You should define them in
> a .cpp file. This way data doesn't get duplicated across multiple
> files that include the .h file.
>
> #include is nothing more than a dumb preprocessor you see. So
> anything in a .h file gets put into all the .cpp files that include
> it. So you've got the same data defined multiple times now if you
> have multiple .cpp files that include that .h of yours. If it's
> only 1 .cpp it might not be a problem, but I'd really avoid it if I
> were you just on good coding practice grounds.

That is a good idea... I have an #ifndef condition in that .h file,
but I had the #endif only protecting calls into other header files.
I moved the #endif to the last line in the .h file and ran the plugin
again with the same result.

_______________________________________________
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>

Re: Plugin crashes... need help
Date: 26.07.06 00:44 (Wed, 26 Jul 2006 00:44:22 +0100)
From: Theodore H. Smith
What's your method declaration then?

> That is a good idea... I have an #ifndef condition in that .h file,
> but I had the #endif only protecting calls into other header
> files. I moved the #endif to the last line in the .h file and ran
> the plugin again with the same result.

No. Just cut and paste those into a proper definitions .cpp file, the
way all the other plugin authors including me do it. Do not put data
into .h files.

Even if it doesn't fix the problem now, it'll save you a problem in
the future.
_______________________________________________
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>

Re: Plugin crashes... need help
Date: 26.07.06 03:05 (Tue, 25 Jul 2006 22:05:18 -0400)
From: Phil M
On Jul 25, 2006, at 7:44 PM, Theodore H. Smith wrote:

> No. Just cut and paste those into a proper definitions .cpp file,
> the way all the other plugin authors including me do it. Do not put
> data into .h files.
>
> Even if it doesn't fix the problem now, it'll save you a problem in
> the future.

I don't see how this would matter, but I will try it tomorrow
morning. I was getting some weird crashes before, so I rewrote and
combined some of my code and they did not crash... so it sounds like
you have a valid point.

So are you saying that you put all code your code for the entire
plugin into a single .cpp file?

_______________________________________________
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>

Re: Plugin crashes... need help
Date: 26.07.06 12:16 (Wed, 26 Jul 2006 12:16:56 +0100)
From: Theodore H. Smith

On 26 Jul 2006, at 03:05, Phil M wrote:

> On Jul 25, 2006, at 7:44 PM, Theodore H. Smith wrote:
>
>> No. Just cut and paste those into a proper definitions .cpp file,
>> the way all the other plugin authors including me do it. Do not
>> put data into .h files.
>>
>> Even if it doesn't fix the problem now, it'll save you a problem
>> in the future.
>
> I don't see how this would matter, but I will try it tomorrow
> morning. I was getting some weird crashes before, so I rewrote and
> combined some of my code and they did not crash... so it sounds
> like you have a valid point.
>
> So are you saying that you put all code your code for the entire
> plugin into a single .cpp file?

No.

One file has the REALmethodDefinitions.

Other files have the functions.

You can put the REALmethodDefinitions into the same file as the
functions, spread the definitions out, just don't put them into EVERY
file!!