Why Does This Fail in API2?

Hey guys,

I have some code that just crashes under API 2. An exception is thrown but then the program just quits w/o the exception being handled. But I don’t know why the exception is being thrown. Here is the code:

If SourcesList.SourceList.CellTag(i,0) <> Nil Then r.PictureColumn("Image") = SourcesList.SourceList.CellTag(i,0) End If

r is a Database Record. SourcesList.SourceList is a listbox inside a container control. The CellTag of that column of the listbox is either going to be NIL or an image - nothing else.

I know the Database Record class is deprecated. But shouldn’t it continue to work? I’m getting an unsupported format exception on this line. The code works fine compiled in older versions of Xojo before API2. I found this quite by accident as it’s a bit of code that hasn’t been touched in a long time.

I am sure I can fix this by going to the DatabaseRow class and using the new APIs. But I don’t have the time right now and would like to know if this should still be working.

Code like this is hard to debug.

Please put result of cell tag in a variable.
Maybe a picture one?

this way you would see whether it happens because of the left or the right of the assignment and you can see value in debugger.

And did you read message for exception?

There is a picture in the cell tag. That is not the problem.

Under APi1 the code is fine. Under API 2 with DatabaseRecord being deprecated the code fails.

The exception message was nothing useful. Says the item is in an unusable format which is not true.

And then after the exception the program just crashes. No exception handling.

What does crash report say for the call stack? (top 10 is probably enough)

As far as know PictureColumn calls to C++ code, which may simply not handle some newer form of picture.
is that a bitmap one or maybe one with several resolutions?

Please report crash via feedback.

OK Christian. I am not sure why I am not getting through here. Maybe my writing is not clear enough:

Let me try again:

This exact same code was written years ago and the database file being read/written was done years ago. Under API 1.0 this all was fine and worked as it should.

There is nothing more to explain than that statement. Xojo goes to API 2.0 and deprecates the DataBaseRecord class and this happens. The picture is an icon size -very small. Hundreds of pixels (or less) at most not thousands. One resolution. It’s a PNG file that was loaded and saved in the picture column of the database. It’s not a newer form of picture.

Here is the crash report from the compiled app:

[code]Process: MediaSwitcher [10870]
Path: /Users/USER/Documents/*/MediaSwitcher.app/Contents/MacOS/MediaSwitcher
Identifier: com.justaddsoftware.mediaswitcher
Version: 4.2.9 (4.2.9.3.537)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: MediaSwitcher [10870]
User ID: 501

Date/Time: 2020-02-13 13:32:38.906 -0600
OS Version: Mac OS X 10.12.3 (16D30)
Report Version: 12
Anonymous UUID: 9B28CB36-F481-F45E-1A7E-88FE3E3ECEEC

Time Awake Since Boot: 4600000 seconds

System Integrity Protection: disabled

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000030
Exception Note: EXC_CORPSE_NOTIFY

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]

VM Regions Near 0x30:
–>
__TEXT 0000000101ed9000-000000010975c000 [120.5M] r-x/rwx SM=COW /Users/USER/Documents/*/MediaSwitcher.app/Contents/MacOS/MediaSwitcher

Application Specific Information:
Performing @selector(performClick:) from sender XOJButton 0x608000347220

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.xojo.XojoFramework 0x0000000109f5fadf MemoryBlockToStringOperator + 17
1 com.xojo.XojoFramework 0x0000000109f1ba0e DatabaseRecordPictureColumnSetter + 47
2 com.justaddsoftware.mediaswitcher 0x000000010201c20b DatabaseRecord.=PictureColumn%%ossi8o + 11
3 com.justaddsoftware.mediaswitcher 0x00000001053ee97c NewPrefsWindow.NewPrefsWindow.OKCancelControl1_OKAction%%o<NewPrefsWindow.NewPrefsWindow>o<OKCancelControl.OKCancelControl> + 727500
4 com.justaddsoftware.mediaswitcher 0x0000000103f4b58b OKCancelControl.OKCancelControl.RightButton_Action%%o<OKCancelControl.OKCancelControl>o + 123
5 libsystem_trace.dylib 0x00007fffea708c3d _os_activity_initiate + 61
6 com.apple.AppKit 0x00007fffd3bf0c9c -[NSApplication(NSResponder) sendAction:to:from:] + 456
7 com.apple.AppKit 0x00007fffd36d6460 -[NSControl sendAction:to:] + 86
8 com.apple.AppKit 0x00007fffd36d6388 __26-[NSCell _sendActionFrom:]_block_invok[/code]

Looks like Xojo did monkey with the codeine screwed up in the MemoryBlockToString function. That’s not mine. That’s theirs. But what good is it to post a bug report about a deprecated item? Deprecated items by definition aren’t maintained or fixed.

What if you specify format and quality?

Maybe the default format was inadvertently changed by Xojo to an Old/Unsupported format?

Xojo keeps telling that existing code using API 1 is continuing to work with no changes. So this could be considered a regression that needs to be fixed. It’s certainly worth reporting that one.
But I agree - chances are low to get a fix (in the API 1 variant) for something that is “known-broken” and needed to be fixed years ago. That is - if this hasn’t been just “aliased” to an API 2 name. So for some cases we might see fixes (in the API 2 variant) which therefore also fixes something if called using API 1.

This method crashes every time it is called. I created a simple app with a 100x100 picture (call it TheImage) added to it and the following two lines of code:

Dim r as New DatabaseRecord r.PictureColumn("Image") = TheImage

Same thing. Definitely a regression.

<https://xojo.com/issue/59185>

Since there seems no way around the crash, I’ve updated a bunch of my code to now use DatabaseRow instead of DatabaseRecord. It’s a pain but at least it works.

I think what’s happening is that the new DatabaseRow.Picture method requires a format as a parameter when you are assigning a picture to the record. That’s not the case with DatabaseRecord. And how do I know what format a picture is? I’ve got cases where people drop a JPEG or PNG or possibly other formats onto a window and then I save those. So what happens when a user drops a JPEG but I specify Picture.Formats.PNG as the parameter?

The picture has no format.

And I’d suggest PNG always as it can handle alpha channel.

The docs for DatabseRecord.pictureColumn says [quote]This item was deprecated in version 2019r2.
Please use DatabaseRow.BlobColumn as a replacement.[/quote]
A workaround might be

row.blobColumn("Image") = theImage.getData(Picture.FormatPNG)
or whatever your preferred data format is…

<https://xojo.com/issue/59185> marked as fixed, thanks William

Yeah, that was fast. He must have looked at it and gone “Duh! Dumb mistake!” What I call a “Duh” bug.