Repository: godot
Issue: MeshDataTool corrupting meshes in Forward+ rendering method
Labels: discussion,topic:3d

### Tested versions

- Reproducible in: v4.3.dev6 \[[64520fe67](https://github.com/godotengine/godot/commit/64520fe6741d8ec3c55e0c9618d3fadcda949f63)\], v4.2.2.stable, v4.1.4.stable, v4.0.4.stable, v4.0.0.stable

### System information

Godot v4.2.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (NVIDIA; 31.0.15.5123) - 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz (16 Threads)

### Issue description

I'm running into an issue where 3D models (unmodified default cube & UV sphere from Blender 4.1 exported as .GLB) are getting corrupted, turning solid black and changing size, after creating a MeshDataTool from their surface and re-committing it to the mesh.

The following barebones script causes the issue to occur:
```
extends MeshInstance3D

func _ready():
	var mdt = MeshDataTool.new()
	mdt.create_from_surface(mesh, 0)
	mesh.clear_surfaces()
	mdt.commit_to_surface(mesh)
```

The docs include a warning that MeshDataTool can only be used on Meshes that use the PrimitiveType Mesh.PRIMITIVE_TRIANGLES (3), but if you modify the script to print it out, you can confirm that this is not the issue.

```
	print((mesh as ArrayMesh).surface_get_primitive_type(0)) # Prints 3
```

The MRP scene contains 5 meshes, left to right: cube and sphere with the barebones script, cube and sphere with [the example MeshDataTool script from the Godot docs](https://docs.godotengine.org/en/stable/tutorials/3d/procedural_geometry/meshdatatool.html#using-the-meshdatatool), and finally, the only working one, the previous script but using a procedurally generated sphere mesh made with [the example ArrayMesh script from the Godot docs](https://docs.godotengine.org/en/stable/tutorials/3d/procedural_geometry/arraymesh.html#setting-up-the-arraymesh).

Editor screenshot:
![Godot_v4 2 2-stable_mono_win64_2024-05-06T033144 905](https://github.com/godotengine/godot/assets/58245404/55f4962a-9352-4b81-a466-c9dac50988c0)

Forward+ rendering method build:
![Godot_v4 2 2-stable_mono_win64_2024-05-06T064649 384](https://github.com/godotengine/godot/assets/58245404/b4e01c8a-85c0-44fd-a5af-2a67b9cd5e66)

Mobile rendering method build:
![Godot_v4 2 2-stable_mono_win64_2024-05-06T064712 477](https://github.com/godotengine/godot/assets/58245404/623ed713-41b0-4ce7-91fa-649116a02d5b)

This honestly makes zero sense to me and I have no idea what's happening here or how any of the involved steps even could go wrong. Whether it's somehow an issue with the models, the import process, MeshDataTool, or why it changes depending on the rendering method. I've tried asking in the Discord server a couple times, but the only lead that's been found is that it works when using the mobile renderer.

### Steps to reproduce

Open the attached MRP in any Godot version 4.x. The selected rendering method is Forward+, and when running the project, you should see the above graphical glitch. If you switch the rendering method to Mobile and save and restart the project, it will look correct when running.

### Minimal reproduction project (MRP)

[MRP_MeshDataTool_ForwardPlus_Issue.zip](https://github.com/godotengine/godot/files/15222036/MRP_MeshDataTool_ForwardPlus_Issue.zip)