Can I make this "null error" fail silently?

Hi all,

I've got an issue with my game, which I've personally never seen, but it occurs on certain hardware configurations (particularly slower configurations).

It looks like this:

1645558469866.png


It occurs if I call Show Picture, then call Move Picture moments afterwards. Like, look at this - this has been known to cause it for these users. It seems to be one of these instances:

1645558441127.png

  1. A "Show Picture" call happens,
  2. 1 frame wait,
  3. then "Move Picture" happens

The only explanation I can figure out is that MV is trying Move Picture before the image fully loads, and as a result, it's getting a "null" or bad data during the process, and it throws up the error.
It might be because the images are encrypted and take longer to load?

I can guarantee the logic is correct. It's iron-clad. It's the sort of thing that, if it was to go wrong, logically would either go wrong every time, or at the very most, 1-out-of-3 times for something that occurs hundreds of times in this section - so there's no way that any user could get through this if the logic wasn't right.

We've now had thousands of players and this has only happened to a very small number (~15) of users on certain hardware configurations (like this literally never happens for me, on my machine).

This suggests to me that the function to move a picture doesn't have a null-check, which is a pretty standard feature for game-engines. While in development, it's fine to have this happen, it's best if the game can continue if this happens in release, because running on past the error is usually going to give a better result than just stopping.

I'm aware the immediate thought here might be "you should re-engineer this not to occur instead of relying on it to fail silently" but I don't want to get into a debate about development standards - game engines can normally "play on" from very slight problems like this.

If I can get this to play on, it would just be a momentary glitch and the users would be past it soon enough. What happens above is the "show picture" actually "spawns" the image offscreen, and then the "move picture" moves it onscreen; so if it failed silently, the user just wouldn't see a picture, and that wouldn't cause a huge issue if it's this rare.

Given how the build is now on Steam/Itch and these problems are so rare, I'm not keen on climbing inside the system again to fix something that I can't actually see on my hardware; we're more likely to cause a new problem through human error than fix it.

Before I look at a classifieds thread, I just want advice. Would it be possible to write a plugin that...
  1. Performs a null-check for the move picture command. If the data is null, the move should not happen - but it must fail silently and progress.
  2. Does the same for the erase picture command, just in case
Is that possible? Would that work? It'd ensure that this issue, in this situation, just doesn't happen?

And potentially - has anyone already done this?
The problem I see with that idea is that "of null" (or "of undefined") are not single errors, but a class of errors.
You are correct in assuming that it basically means the engine tried to access a data object that does not exist - for whatever reason.

And while it is possible to make a blind error handler that returns without a message, that will affect all "of null" errors - even those that have nothing to do with your pictures.
And it has the additional problem that a continuation would require the computer to be able to identify the missing data to know where it is needed next - something very difficult because "of null" has nothing to analyse what exactly is missing at that point.
Theoretically, if it's always happening in that specific scenario and you know what function it's coming from (you don't show your error trace), it should be possible to add a quick check to see if whatever variable you expect to manipulate is null and skip back out of the function if it is. It's not necessary to do something that would squash all "null" errors from all sources in your entire project.

The trick could be what effect that has afterward. For example, if it is due to loading the "moving" image, if Frame C refers to the existing image and redraws it in a slightly different place, but that doesn't exist because it didn't load in Frame B, will it still be there from Frame A to get references from? It may not be as simple as just skipping one frame in your animation.

Hopefully someone who's more conversant with the lower level guts of this process can give you an answer.
The trick could be what effect that has afterward. For example, if it is due to loading the "moving" image, if Frame C refers to the existing image and redraws it in a slightly different place, but that doesn't exist because it didn't load in Frame B, will it still be there from Frame A to get references from? It may not be as simple as just skipping one frame in your animation.

After the move, the picture stays onscreen (motionless) for several seconds; then it moves offscreen, and then erases.

So it forgoing the move (here or anywhere in the game) shouldn't cause any problems.

I would love to be able to isolate what hardware quirk is leading to the problem, because, as I've said, I've never seen this on my machine (I mean, I've seen the null error, but only when I've got a genuine, repeatable logic problem).

It might be an issue related to Intel onboard graphics? Something like that. But I'm not sure.
After the move, the picture stays onscreen (motionless) for several seconds; then it moves offscreen, and then erases.
I understand what the effect being produced is, but if you read my prior post I'm talking about the code logic.

Let's say you're in line to pick up food in a restaurant, and you give each person the instruction "Take a step forward when the person in front of you takes a step forward."

Then you choose one person and take them out of line. The person behind them no longer has a person in front of them to refer to, so they'll never step forward, which means no one behind them will, either.

So it depends on how JS does lower level image handling generally, and how this presumed loading error is handled specifically, skipping a frame could break the rest of the process.
I've had a look at the RPG Maker MV code, and I honestly don't see how a Move Picture command can cause a "Cannot read property 'width' of null" error.

Pictures are separated into Game_Picture (managed by Game_Screen), and Sprite_Picture (managed by Spriteset_Base).

Showing a picture basically just creates a Game_Picture, which is added to the Game_Screen. Moving it simply modifies the properties of the Game_Picture. That's all that happens on the game logic side. In fact, the engine already does a null-check. If the desired Game_Picture does not exist, nothing happens.

The actual rendering process is handled on the Sprite_Picture side. This is extremely complex, so I only had a superficial look, but the Spriteset_Base creates 100 Sprite_Picture instances and keeps them in an array. These Sprite_Picture instances are always there, whether they're needed or not. From my experience, objects that are directly connected to rendering are reused a lot, so this is most likely for performance optimization.

The array is then added to the render tree, which is then handled by Pixi.js on each frame. When Pixi.js wants to render a frame, the Sprite_Picture asks the Game_Screen for the Game_Picture with the same ID as the Sprite_Picture. In most cases, that is null, and the Sprite_Picture just sets its own bitmap to null (and Pixi.js just doesn't render anything for that Sprite_Picture). If there is a Game_Picture, however, the Sprite_Picture will ask the ImageManager to load the corresponding bitmap. The bitmap is either already in the cache, or will be loaded asynchronously (while the game is still running).

The thing is, this whole bitmap loading business already happens as early as the Show Picture command. If that's the cause of the crash, your game should've already crashed then, not just during the Move Picture command. In fact, your game should've crashed as soon as it's trying to display any image, since all pictures (sprites, windowskins, tilesets, etc.) are loaded in the same way using the ImageManager.

Long story short: I don't think the issue is caused by the Move Picture command itself. I think the problem is much more obscure than that. This bug is going to be near impossible to fix without a way to reliable reproduce it, I'm afraid.
For experiment, what happens if you extend the wait time? Is there a base wait time under which the game crashes?
For experiment, what happens if you extend the wait time? Is there a base wait time under which the game crashes?
Unfortunately it's not consistent.

I can't do it on my machine, ever. And even for other people, it doesn't happen every time on slow machines. I even tried making a slow virtual machine on my computer, and still, I couldn't see it. So I'm wondering if there's some specific hardware situation at work here.
I don't think the issue is caused by the Move Picture command itself. I think the problem is much more obscure than that.
yes and no - similar errors can easily be reproduced by erasing the picture to be moved before the move command, and as such it is known to cause problems if you have move picture and erase picture independent of each other.
in this case part of the problem is probably the variable name that is part of the reference as such is known to cause problems with nonexisting filenames as well.

And even for other people, it doesn't happen every time on slow machines.
as said by the other poster above, you need to get the errortrace from the console output to have even a chance of finding the true cause for this error.
either ask your playtester to press F8 the next time this happens, or update your yanfly core to the version that diesplays most of the errortrace on the regular error screen.
in this case part of the problem is probably the variable name that is part of the reference as such is known to cause problems with nonexisting filenames as well.
I'll need to try, as I would be shocked if it's that string logic for the filename. It wouldn't make sense that it works nearly all the time, but not sometimes for specific people's computers.
that is why I said we need the full error trace to determine what exactly is missing/null
Hi there!

Like Nolonar, I also take a look into the default RM code and almost get to the same conclusion - in cases, you are not using any plugin.

The thing is, you probably use. So, the "width" error can only happen on a sprite(in our case Sprite_Picture), because Game_Picture does not have a width property(by default).

If we take a look at the Sprite_Picture, we will see that it only load the bitmap if there is a picture, and it only updates the rest of their settings, when it is visible. And it is only visible when a picture exists:

JavaScript:
Sprite_Picture.prototype.update = function() {
    Sprite.prototype.update.call(this);
    this.updateBitmap();
    if (this.visible) { // It is visible! So we can update other stuff.
        this.updateOrigin();
        this.updatePosition();
        this.updateScale();
        this.updateTone();
        this.updateOther();
    }
};

Sprite_Picture.prototype.updateBitmap = function() {
    var picture = this.picture();
    if (picture) { // Picture exists!
        var pictureName = picture.name();
        if (this._pictureName !== pictureName) {
            this._pictureName = pictureName;
            this.loadBitmap(); // Load the bitmap!
        }
        this.visible = true; // Set visibility to true!
    } else {
        this._pictureName = '';
        this.bitmap = null;
        this.visible = false;
    }
};

Sprite_Picture.prototype.loadBitmap = function() {
    this.bitmap = ImageManager.loadPicture(this._pictureName);
};

So, on the updateBitmap function, we see that he fires the command to load the bitmap and after that, it set the visibility to true. But, just because it sets the visibility to true after the loadBitmap command, does not mean that the bitmap is really loaded.
And, as you say that the error only happens on slower configurations, I believe due to some interference of other plugins(or who knows what xD), maybe it will be safe to add a load listener to the bitmap and only set the visibility to true when the bitmap is really loaded.

So, in a long shot, I would try to copy and paste the below as a plugin, and put it above everything else on the plugin manager, since he overwrites the Sprite_Picture updateBitmap(Or insert it inside your first plugin file that your game has. Because adding another plugin can "corrupt" older save files).

JavaScript:
Sprite_Picture.prototype.updateBitmap = function() {
    var picture = this.picture();
    if (picture) {
        var pictureName = picture.name();
        if (this._pictureName !== pictureName) {
            this._pictureName = pictureName;
            this.loadBitmap();
        }
        //this.visible = true; REMOVE this line
    } else {
        this._pictureName = '';
        this.bitmap = null;
        this.visible = false;
    }
};

var _Sprite_Picture_loadBitmap = Sprite_Picture.prototype.loadBitmap
Sprite_Picture.prototype.loadBitmap = function() {
    _Sprite_Picture_loadBitmap.call(this)
    this.bitmap.addLoadListener(() => {
        this.visible = true
    })
};

This is just a long shot, just a hint. The best thing will indeed have the console log error.
Hi there!

Thanks Eliaquim; I put that into an existing plugin (I already have a top-of-the-list plugin with a bunch of snippets), and a user who has had this problem is going to try it.
if you use MV, you can use the plugin [MrTs_ErrorStack] which shows
the error from the console log into the screen which you can also
backtrace the problem.

I dont know if it only shows the first 8 if not 20 on screen, but it could
help you a bit in this case too for the true cause and why it shows.

but it's your closest option for the people that got the error.
or update your yanfly core to the version that diesplays most of the errortrace on the regular error screen.

The user in question (and the launched game) were using v1.31, which is supposed to do this, according to the changelog.

Is there a key chord or something to get this to show? This user can't hit F8 as that doesn't work in release builds.
if you use MV, you can use the plugin [MrTs_ErrorStack] which shows
the error from the console log into the screen which you can also
backtrace the problem.

I dont know if it only shows the first 8 if not 20 on screen, but it could
help you a bit in this case too for the true cause and why it shows.

but it's your closest option for the people that got the error.

Sadly this won't work. Just realised, I'm already using the version of YEP_CoreEngine that does this - thanks to your post, I was able to see the screenshot of what it should look like, and yeah, during development I've seen it many times so I know it should work.

But what the user sees is still what I showed above.
Just to update on this; tried @Eliaquim 's solution, sadly it didn't work.

I also have two parallel events in this map which control some aspects of the onscreen interface; we tried disabling them completely to see if that would remove the problem, and it had no effect.

Potentially going to try a few changes; we might do a version where we reduce every "picture" to a 1x1pixel empty PNG, for the absolute smallest file, and see if that makes any difference.
The next thing is to start ripping things out of the map until the problem ceases to occur.

Original thread: https://forums.rpgmakerweb.com/threads/can-i-make-this-null-error-fail-silently.145153/