### Godot version

4.0b16

### System information

Windows 11

### Issue description

Godot game (not the editor) crashes by loading a specific ".glb" model via `Godot.GltfDocument.AppendFromFile` (in C#, not tested in GDScript). The model is exported via Blender, and runs on Godot 4.0 Beta 15 without any problems.

```
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication t.
   at Godot.NativeInterop.NativeFuncs.godotsharp_method_bind_ptrcall(IntPtr, IntPtr, Void**, Void*)
   at Godot.NativeCalls.godot_icall_4_467(IntPtr, IntPtr, System.String, IntPtr, UInt32, System.String)
   at Godot.GltfDocument.AppendFromFile(System.String, Godot.GltfState, UInt32, System.String)
   at dummy_scene._Ready()
   at Godot.Node.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name ByRef, Godot.NativeInterop.NativeVariantPt)
   at Godot.Node3D.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name ByRef, Godot.NativeInterop.NativeVariant)
   at dummy_scene.InvokeGodotClassMethod(Godot.NativeInterop.godot_string_name ByRef, Godot.NativeInterop.NativeVariantP)
   at Godot.Bridge.CSharpInstanceBridge.Call(IntPtr, Godot.NativeInterop.godot_string_name*, Godot.NativeInterop.godot_v)
```

![image](https://user-images.githubusercontent.com/18738917/215181154-998d84b9-247b-4e8d-a1de-9bf400a1e567.png)


### Steps to reproduce

Run the dummy scene with affected GLTF code. (See MRP.)

### Minimal reproduction project

C# proj [Godot 4 b16 GLTF Crash.zip](https://github.com/godotengine/godot/files/10522482/Godot.4.b16.GLTF.Crash.zip)

GDScript proj [Godot.4.b16.GLTF.Crash.gdscript.zip](https://github.com/godotengine/godot/files/10543553/Godot.4.b16.GLTF.Crash.gdscript.zip)

mat = import_mesh->get_surface_material(surface_i);
			}
			if (mat.is_valid()) {
				HashMap<Ref<Material>, GLTFMaterialIndex>::Iterator material_cache_i = p_state->material_cache.find(mat);
				if (material_cache_i && material_cache_i->value != -1) {
					primitive["material"] = material_cache_i->value;
				} else {
					GLTFMaterialIndex mat_i = p_state->materials.size();
					p_state->materials.push_back(mat);
					primitive["material"] = mat_i;
					p_state->material_cache.insert(mat, mat_i);
				}
			}
			if (targets.size()) {
				primitive["targets"] = targets;
			}
			primitives.push_back(primitive);
		}
		Dictionary e;
		e["targetNames"] = target_names;
		weights.resize(target_names.size());
		for (int name_i = 0; name_i < target_names.size(); name_i++) {
			real_t weight = 0.0;
			if (name_i < p_state->meshes.write[gltf_mesh_i]->get_blend_weights().size()) {
				weight = p_state->meshes.write[gltf_mesh_i]->get_blend_weights()[name_i];
			}
			weights[name_i] = weight;
		}
		if (weights.size()) {
			gltf_mesh["weights"] = weights;