Null pointer exception when adding custom class

A few weeks ago, I had a discussion on Discord with uckelman and Swampwallaby about this problem.
Since then I have spent quite some time trying to figure out, what is going on - to no avail.

I hope you guys are willing to help by taking another look. I have uploaded a test module, my very simple custom class and a video demonstrating the problem to my cloud server. You can find it here https://cloud.observator.dk/index.php/s/XYoP5g6tfiyZXeL?

thx

I think there’s a bug in how custom classes are imported. We’ll get back to you soon about this.

I found the problem—I should be able to get you a test build tomorrow.

I know what the problem is.

I agree Joel, it probably is a bug in the import not calling addTo early enough. It doesn’t affect any other classes though, just HexGridNumbering which is unusual because it has the in-built grid visualiser which has a paint() class which is being called before addTo.

You could fix the import action, or you could just add if (grid == null) return to the visualizer paint() method.

The work around is to add a standard Hexgrid numberering to your module and save it. Then edit the buildfile and change

<VASSAL.build.module.map.boardPicker.board.mapgrid.HexGridNumbering …>

to

<your.packahe.and.class.name …>

Regards.

What Brent described is exactly what I found last night.

I think the right approach is to make adding a built-in object do the same as adding a custom one, viz. call addTo() first.

Please try the VASSAL-3.7.0-SNAPSHOT-b14247e-uniform_add_action build from our builds archive. Does this fix the problem for you?

@Brent_Easton Does the change here look correct to you?

There’s quite a bit more machinery that the regular “Add” action does to make sure that adding works as you’d expect (e.g., automatic removal when you Cancel), so I tried to unify both Add and Import.

Done. Looks good to me.

1 Like

I have tried the snapshot you referenced - and it indeed solves the problem.

For good measure I also tried inserting the std. HexGridNumbering class and found no side effects there.

Thx for your quick help

1 Like

Thank you for providing such a thorough bug report. That helps us make efficient use of our time.

The fix will appear in 3.7.0-beta5. Until then, if you want to keep using that snapshot, it shouldn’t cause you any problems to do so.