Moving to HiDPI - NilObjectExceptions everywhere

I’ve got a project I’m testing out with the new(ish) HiDPI option. Nearly all of the images were added before and reside in the project as a picture reference instead of an image set.

With HiDPI enabled there are many situations where referencing those pictures directly is causing NilObjectExceptions. Not sure if this is how it’s supposed to work, but something as simple as creating a pointer to the picture will throw this exception (MyImage below was a jpg dragged into the project, for example):

dim p as picture = MyImage //NilObjectException

I’m also getting a NilObjectException when trying to recreate the picture by painting it manually:

dim p as picture = NewPicture(32,32,32) p.graphics.DrawPicture MyImage,0,0 //NilObjectException

In addition to this, previously in code (before there was the option to set the mask for an image) I would simply set the mask for an image when it is first used in the app, something like:

MyImage.mask.graphics.DrawPicture MyImageMask,0,0

This too will cause NilObjectExceptions. This one I’ve been able to go through the app and remove this situation and simply select the mask in the project navigator, but I couldn’t find any mention of this change in the release notes.

I think you need to remove the pictures then re-add them.

I’m just now realizing this after trying that on one… and it’s only happening for some images yet for not others…

Is there any good way of doing this for existing projects? There are hundreds/thousands of images in this one project, some work fine, some don’t. And to get the ones that don’t work I have to pull them out, apply the mask in photoshop, save as a PNG, then reimport into my project?

I guess your pictures causing trouble have “transparent” set to white (in the IDE). Try setting Transparent to none.

They were set to none. Seems that some of the images will cause a NilObjectException no matter what I do until I remove them, apply the mask externally and resave them, and then reimport into the project. The problem is there is no way at all to figure out WHICH images encounter this issue, so I have to try to find when every single image resource is used in code.

So your problem pictures have Transparent None but the Mask is set to another Picture.

Some testing shows if the Mask is set to an old-school Picture then there’s a NilObject, but if the Mask is an ImageSet Picture then it runs OK.

So you could remove just the Mask Picture and re-add it as ImageSet then re-set the Mask option. That solves fiddling with Photoshop but leaves having to identify all the problem pics.

I’d save the project as XML (or VCP), investigate the format a bit to come up with a quick and dirty app that will list all the pictures. A little more code can merge the Picture and Mask so you don’t have to use Photoshop, and build a folder of updated pictures. Then in the IDE delete all Pictures and drag the new ones in.

Clears the images from the project,
Put all images into a single (or more) folders,
Drop that (there) folder(s) into the Project Navigation Pane.

I’ve set a sarch for ImageSet @ developer.xojo.com and I get:
Sorry your search did not return any results.

Thus my question: what is an ImageSet ?
(and eventually how do we create them ?)

A second search leads me to iOS *
http://developer.xojo.com/userguide/ios-retina-images

  • I only recently started to use developer.xojo.com (any previous search always returned iOS data useless to me).

If you have HiDPI enabled in your project, dragging an image to it will create an image set instead of just a link to that individual image file. Image sets link multiple images for use at different resolutions. iOS has this on by default and I’m pretty sure all images are imported as image sets.

Anyway, sounds like this issue is just one of those “spend a few weeks going through everything” problems. I can’t remove and put back all of the images when some are older formats, some have masks, some don’t, etc, etc. I’m just trying to search for any use of the work mask (which there are over 3k in the project) and trying to run around the app to have it throw NilObject errors to show me which images are affected.

Thank you Tom for the explanation.

Depending on the image file names, you can do your way using OS X search feature (unless you are on Windows):

  1. Open the folder where yur images resides,
  2. Cmd-f
  3. Click in the name of that folder (not “Thiis Mac”),
  4. Type -Mask (for example) to exclude files with Mask in their names,

you get the idea. Not knowing the file names schema you use, I cannot tell more.

Nota: You can put part of a file name in the search field, wait a bit 'till OS X propose to set the search to that, then add more text, etc.

Where are the MacOS User’s Manual we had 20 years ago !

You should also keep in mind that pictures dragged into the IDE or loaded with Picture.Open are also now immutable. As a result, the RGBSurface and Graphics objects are now nil.

There are a couple of reasons for this:

  1. Pictures are now loaded on demand from disk.
  2. Multi-res pictures wouldn’t have any way to know which graphics or rgbsurface to use.

Picture.Open and ImageSets with a single representation do have read-only RGBSurfaces. These are ImmutableBitmap type.

If there’s multiple representations then it’s Image type where RGBSurface is nil.