# Problems...



## martinatkinson (Feb 23, 2002)

Hello!

I am having problems with the application I am trying to program.  It is an app called "History Helper" and I have to make it save and open in text views as RTF files.

Here is what I have in my Document.m file:

#import "Document.h"

@implementation Document

- (NSString *)windowNibName
{
    return @"Document";
}

- (void)windowControllerDidLoadNibNSWindowController *) aController;
{
   [super windowControllerDidLoadNib:aController];
   if (fileContents)
    {
       [textView replaceCharactersInRange:NSMakeRange(0,0) withRTF:fileContents];
       [fileContents release];
       fileContents = nil;
    }
}


- (NSData *)dataRepresentationOfTypeNSString *)aType {
    NSAssert([aType isEqualToString"rtf"], @"Unknown type");
    return [textView RTFFromRange:NSMakeRange(0, [[textView textStorage] length])];
}


- (BOOL)loadDataRepresentationNSData *)data ofTypeNSString *)aType {
    NSAssert([aType isEqualToString"rtf"], @"Unknown type");
    fileContents = [data copyWithZone:[self zone]];
    return YES;
}

@end

For some reason when I test this out and try to open an RTF file it gives me an error as follows "2002-02-23 11:51:14.249 PowerText[4025] *** Assertion failure in -[Document loadDataRepresentationfType:], Document.m:31
2002-02-23 11:51:14.253 PowerText[4025] Unknown type"

Do you have any suggestions?

Thank you so much!

Albert


----------



## serving2masters (Feb 23, 2002)

My guess would be a problem of case. - like it's sending in "RTF" and that's not getting accepted as "rtf".

I'd just add a 

printf("%s\n", [aType cString])

on the line above the assertion in loadDataRepresentation and see what it's actually sending in.


----------



## martinatkinson (Feb 24, 2002)

Hello!

It prints the string "Rich Text Document" and then the rest of the errors in my debugging window.  By the way, "Rich Text Document" is the name of my DocumentType.  Any suggestions?

Thanks!

Albert


----------



## serving2masters (Feb 24, 2002)

Well, I'd suggest getting rid of the assertion. If you defined just one document type in the "Target"/"application settings" place, then the Open dialog will only let the user open one kind of file, so you shouldn't need to check what kind it is.


----------



## martinatkinson (Feb 24, 2002)

Hello!

Thank you so very much for fixing this problem.  The removal of the assertion did work and now I can move onto other parts of History Helper.

Have a great day!

Albert


----------



## martinatkinson (Feb 24, 2002)

Hello!

I have another problem, same app, same code.  My problem is this: if I close all the document windows and then try to open a document it crashes because of "signal 10 (SIGBUS)"  Also, if I close all the windows and then switch to another application, then switch back to my app it will crash because of "signal 6 (SIGABRT)"

Any suggestions?

Thanks so very much!

Albert


----------



## serving2masters (Feb 24, 2002)

Uhh... no suggestion but to run the debugger and find out what line those two things happen on. I usually SIGBUS's when I try to use a variable without initializing it.


----------



## martinatkinson (Feb 25, 2002)

Hello!

Uhh, how do you use the debugger?  Stupid question, I know, but I tried the "build and debug" button from inside PB and it gave me nothing.

Well, I ran the application with MallocDebug and it still crashed but gave me a cryptical message.  Can you translate and does this have anything to do with why it is crashing?

Thanks!

Albert


----------



## whitesaint (Feb 26, 2002)

this line:

([aType isEqualToString"rtf"])

the string should be defined in Info.plists like this:
MyRTFType = @"NSRTFpboardType"

then in your code:
([aType isEqualToString"MyRTFType"])

everything should be fine.  Sorry if NSRTFpboardType isn't correct, im on a Wintel right now


----------



## martinatkinson (Feb 26, 2002)

Hello!

Actually, whitesaint, I just deleted the whole NSAssert line and it works just fine now.  Except for the fact that closing the last window and then trying to create a new doc, open a doc, or deactivating and then reactivating the app will crash it.  Any suggestions?

I have looked through all my source code and can not find one thing that should be crashing it.  My application is an AppleScript application with Cocoa classes, if any of you guys would be so kind as to skim through my source code and see if there are any problems that you can see that would be very nice, it is at http://www.myfamilycenter.org/appletreesw/PowerText Code.sit  Please do this on your own free time (if you have any  ) as I do not want a newbie like me to get in your way.

Thanks a bunch!

Albert


----------



## serving2masters (Feb 27, 2002)

I looked it over, and the debugger didn't catch the SIGBUS, which makes me suspect the problem is happening somewhere in the applescript stuff. I've never done anything with applescript though, so I don't even know where to look in it. I think if the problem was anywhere in the obj-C though the debugger would catch it.


----------



## martinatkinson (Feb 27, 2002)

Hello!

It is a document-based AppleScript aplication however my Document.applescript does not contain any code.  Could this be a problem?

If anyone else sees anything or has any suggestions please let me know.

Thanks so much!

Albert


----------



## martinatkinson (Feb 28, 2002)

Hello!

Anyone out there have good ASS or PB skills?  I really need your help.  One thing to note is a commented all my AppleScript code, cleaned the project and ran it and then it still quits, so I am unsure of whether or not it is really the AppleScript that is causing problems.

Thanks for your help!

Albert


----------



## simX (Mar 2, 2002)

martinatkinson:

In the course of using AppleScript Studio with Memory Usage Getter, I have found that AS Studio has MORE than its share of quirks and bugs.  I have had times when I have to do a workaround because a seemingly harmless line makes my app quit or generates an error for no reason.  I'm having one of those problems right now, and it's really annoying.  There's really nothing I can do about it, which really sucks.

When I do encounter these problems, though, I find that 3 things help:

1) Delete the "build" folder inside your project's folder.  When building an application, it seems that it actually simply modifies the stuff inside this folder and then runs it, so this could help.

2) Quit Project Builder and relaunch.  Sometimes PB just decides to be quirky (especially when debugging), and a relaunch seems to solve the problem.

3) Logout/restart and login.  This sometimes helps when the previous 2 things don't.

Hope this helps.  If you have any more particular AppleScript questions, I'd be happy to attempt to answer them.


----------



## martinatkinson (Mar 2, 2002)

Hello!

Thank you for your suggestions, unfortunately after trying all of those I still had no luck.  This is really getting on my nerves as I would really like to get this fixed.   Maybe I should just make a Cocoa application instead of trying to do a Cocoa-AppleScript type thing?  Any one else have any suggestions?

Have a great day!

Albert


----------

