Nil Object Exception on Picture Object

Hey all,

I’m seeing some instances in Windows builds where I am getting a NIL Object Exception for a picture object even though I have explicitly defined an image file for that picture. It started as some customers were getting crashes but I had not seen it. Then I put some debugging code into the app and trapped the exception and have it email me an error report whenever it happens. I have now seen it myself. I’m compiling for 64 bit using Xojo 2017R3. Here’s the code. It’s in the CellTextPaint event of a listbox:

In the code below “j” is a network device that we are monitoring. “ln” is a variable for the line number I am on in that routine. I did this so that when the exception occurred, I could email myself where the exception happened in the code. It is happening just after line 93 which is the g.DrawPicture call. That is the only line after setting ln =93 as I increment ln after that call (code not shown). And P is the only thing that could be Nil in that call.

I define p in each branch of the If/Then statement. And there is no other possibility. One of those branches are going to be executed and in each one, p gets assigned a picture. And these pictures are added to the Xojo project as project items. The only thing I can think of is if for some reason, the Windows OS doesn’t give the picture file correctly when the call is made for the assignment…

Ideas anyone?

Thanks!

  If j <> Nil Then
    
    Dim colwidth as integer = val(widths(2))
    ln=44
    If Not ScrollBarHorizontalVisible Then
      colwidth = ((colwidth/100)*Me.Width)
    End If
    
    Dim usethis As Integer = If(colwidth < Me.RowHeight, colwidth, Me.RowHeight)
    Dim mx as integer = Abs((colwidth-usethis)/2)
    ln = 51

// Define the picture object
    Dim p as Picture
    
// Set p to a picture file depending on connected state..
    If j.Connected Then
      p = GreenDot
    Elseif j.AttemptingLogin Then
      p = BallYellow
    Else 
      p = RedDot
      ln = 63
      Me.cell(row,6) = ""
      Me.Cell(row,7) = ""
      Me.Cell(row,8) = ""
      Me.cell(row,8) = ""
      'me.Cell(row,9) = ""
      
      If j.Rebooting Then
        Me.Cell(row,10) = "Rebooting"
      Else
        Me.Cell(row,10) = ""
      End If
      
      Dim mSerialModes As MyPopup
      ln=77

      If DeviceList.CellTag(row,11) <> NIl Then
        mSerialModes = MyPopUp(DeviceList.CellTag(row,11))
      End If
      
      ln=86
      If mSerialModes <> Nil Then
        mSerialModes.ListIndex = -1
      End If
      
      me.Cell(row,11) = ""
    End If
    ln=93
// NOE happening here!! 
    g.DrawPicture(p,mx,0,usethis,usethis,0,0,p.Width,p.Height)
    
  End If
Dim p as Picture

???

No Width, No Height ?

[quote=411499:@Emile Schwarz]Dim p as Picture
???

No Width, No Height ?[/quote]
When you are assigning a picture file to it, you don’t want to pre-specify width and height as that is all in the file. So no.

I’m defining an object and assigning to it another object that already exists (the file). I’m not constructing a new object.

which is Nil? P or G?

Well, I supposed G could be but that would not make sense since G is the graphics property of the control (the listbox) and the listbox is not Nil.

CellTextPaint for a listbox has the following call:

CellTextPaint(g as graphics, row as integer, column as integer, x as integer, y as integer)

I would be very surprised if g passed in by the framework is Nil. I supposed it could be but not sure why.

ah missed that part… :slight_smile:

I see no way to get to the drawpicture without assigning one of the 3 colors , but I assume you knew that already :slight_smile:

So the only thing that makes sense… it one (or all) of the source images have gone walk-about.

If you can reproduce the problem… check RedDot, YellowBall and GreenDot

Sorry, my wrong answer. Because I do not saw a load from a FolderItem I wrongly assumed this was an error. Now, with your answer, I recall that I used that too when I do not know the image file that I will load…

another question:
is GreenDot a Picture ?

Also: did you put a breakpoint and watch how the code performs in the debugger ?

[quote=411504:@Dave S]ah missed that part… :slight_smile:

I see no way to get to the drawpicture without assigning one of the 3 colors , but I assume you knew that already :slight_smile:

So the only thing that makes sense… it one (or all) of the source images have gone walk-about.

If you can reproduce the problem… check RedDot, YellowBall and GreenDot[/quote]

Thank you for confirming that I am not insane or didn’t miss something incredibly obvious. That is what I am wondering - if somehow the picture files have gone walkabout…with all the 64 bit problems in the Windows framework, I wouldn’t be surprised.

[quote=411507:@Emile Schwarz]Sorry, my wrong answer. Because I do not saw a load from a FolderItem I wrongly assumed this was an error. Now, with your answer, I recall that I used that too when I do not know the image file that I will load…

another question:
is GreenDot a Picture ?

Also: did you put a breakpoint and watch how the code performs in the debugger ?[/quote]

Right - I could have used a FolderItem but why when I already have dropped the pictures into the IDE. GreenDot, RedDot and BallYellow are all pictures - PNG files.

I have not seen this in the debugger yet - only compiled builds, but running the debugger on the Windows machine where I saw this is my next step. I wanted to post first to see if somehow I was missing something…

Off the top of my head.

What column are you painting here?
Do you know if all routes through the if above the DrawPicture cause the problem?
Do you error report the values for all variables above the DrawPicture? If so, is there a pattern?
What happens in MyPopUp?
Have you checked for recursive paints using a window event viewer like Spy++?
Have you found out what is Nil?
Does it happen in 32bit?

[quote=411530:@]Off the top of my head.

What column are you painting here?
[/quote]

The column being painted is 3. I get into the code I posted via a Case Statement.

No. I do not.

Again, I don’t. I need to do more research. I was first asking here as a sanity check to make sure I am not missing anything obvious.

This is a pop-up menu that is placed ion the row that is for setting baud rate of an RS232 port that the device has. If the device is rebooting, and the pop-up menu exists (I set the CellTag for one of the columns to be the pop-up menu), then I set its list index to -1. That’s about it.

No, but why would that happen and that would seem like a defect in the framework to allow recursive paints. Even so, the picture object should never be NIL.

There are only two possibilities: Either the picture object is NIL or Xojo is giving me a Nil graphics object. I haven’t tracked that down yet.

[quote]
Does it happen in 32bit?[/quote]

Again - not sure.

Even when you have dropped the picture into the project it could still end up being nil. But someone would have to deliberately take steps to make this happen. If someone removed the item from the built projects Resources then the runtime could return a nil picture. As I said - this would have to be something someone did on purpose.

That’s what my assumption was. However, the NOE is still happening…

I tried that earlier, the project crashes on startup and the crash isn’t trapped by App.UnhandledException but it is caught when running in the IDE though if the image is missing when the project is opened in the IDE.

as a test… try putting this code just before the drawpicture

if reddotl=nil then break
if yellowball=nil then break
if greendot=nil then break
if g=nil then break

it SHOULD break on one of those lines and at least you will know what item to chase

Did you use an image? or a picture?

Here’s the case for this:

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

[quote=411552:@Jason Parsley]Did you use an image? or a picture?

Here’s the case for this:

<https://xojo.com/issue/53848>[/quote]

I dragged a png onto the ide then I assigned that to a picture. Supports Hi-DPI was on (as default)

I do not understand the difference between Image and Picture. Care to Explain ?

Not checked with current Xojo; there is a difference where none have to be.

And, the work-around is to use FileType_Graphics.All:

for forgotten reason (I wrote that in two times):

Dlog.FolderItem = FileType1.SQLite + FileType1.CDB // CDB is a variation of SQLite *

There was a difference in the working flow when I use a .sqlite file vs .cdb.

The trouble ends when I searched why and discover this strange line; I used FileType1.All; that object defines only two entries, the two entries I need.

Xojo 2015r1.

  • Created six years ago, and for compatibility, I never delete it.

A picture is a single graphic entity… what Xojo used for many years
and Image (or Imageset) is multiple “pictures” that are referenced by a single name, and the OS picks the one that matches the resolution need the best (@1x @2x etc)

an ImageSet is refered to the same as a “picture”, but is more flexible

I think I found the problem. It appears that BallGreen and BallRed are NOT in my resources folder in Windows. I have a feeling that when building my .MSI installers, I didn’t make sure that AdvancedInstaller has a proper and updated copy of the resources folder. Had to be that because they are there in the Builds folder. Probably why I never saw this when running on Windows from the builds folder.

Now I have to post an update. Grumble…grumble… >:(