Godot version:
Godot master 1ff170e67f0044b0a9f42fc936f09847c5ec4127
OS/device including version:
Win7/Radeon7870
Issue description:
The mesh previews aren't working when adding a MeshLibrary to a Gridmap as shown below:

The reason for it is that the export of the MeshLibrary seem to not work correctly, as while the actual preview image data is exported:
````
[sub_resource type="Image" id=2]
data = {
"data": PoolByteArray( ... ),
"format": "RGBAHalf",
"height": 64,
"mipmaps": false,
"width": 64
}
````
The ImageTexture subresource has a null image reference:
````
[sub_resource type="ImageTexture" id=3]
image = null
size = Vector2( 64, 64 )
````
I've messed around in the debugger to try to root cause it and while I found what's the problem, I'm not yet familiar enough with the source code to propose a solution.
The problem seems to be that the RES handle referencing the Image object that is stored into ResourceFormatSaverTextInstance::internal_resources is a different one than the RES handle which is used to compare it against in ResourceFormatSaverTextInstance::_write_resource, even though the actual Image object they refer to is the same (the image data object of the preview).
I verified this is the only cause of the problem by manually overriding the lookup in internal_resources to succeed, which resulted in the correct data exported to the MeshLibrary file:
````
[sub_resource type="ImageTexture" id=3]
image = SubResource( 2 )
size = Vector2( 64, 64 )
````
And obviously then the preview image correctly shows up when I use the exported MeshLibrary in a Gridmap:

Again, unfortunately, I didn't yet figure out how and why two RES references to the same Image object can exist, whether that's expected, and if yes, why the internal_resources map uses that as a key, but hopefully this is enough information for someone to figure out the underlying problem.
I've also tried exporting the MeshLibrary in binary form but that makes no difference.
Steps to reproduce:
Minimal reproduction project:
GridmapPreviewBug.zip
Forgot to mention that the issue of not being able to match the RES handle with the one in internal_resources also results in the following error output:
Resource was not pre cached for the resource section, bug?
I have the same issue, I just noticed that when you create the GridMap's MeshLibrary is recently created it works fine, you can see the preview, but if I close the project and reopen, it doesn't.
Forgot to mention that I'm using a custom build 3.1 beta ab843b1.
And that I can see the following message (repeated for each image), in the console:
drivers\gles3\rasterizer_storage_gles3.cpp:1052 - Condition ' !texture->active ' is true. returned: Ref<Image>()
closed via 32fa136
I just tested with latest code ( build 853f985 ), now when I update the library it crashes.
As the window closes too fast, and it seems it does not log into any file I can't paste it here.
There's a small bug in the fix from @reduz, we already discussed it with him. I'll post a PR fixing it tomorrow.
PR #25335 should solve the outstanding issues with this one.
Yeah, it seems to be working now, cool.
Even if, I think that for anyone having an existing project they need to re-import again instead of updating, at least, to me it worked only doing that (I can't actually see the difference between the two).
Most helpful comment
closed via 32fa136