Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving a cube map using "ResourceSaver.save()" doesn't work #54202

Closed
DataPlusProgram opened this issue Oct 24, 2021 · 8 comments
Closed

Saving a cube map using "ResourceSaver.save()" doesn't work #54202

DataPlusProgram opened this issue Oct 24, 2021 · 8 comments

Comments

@DataPlusProgram
Copy link

DataPlusProgram commented Oct 24, 2021

Godot version

3.3.3 stable, 3.3.4 stable, 3.4.rc1

System information

Windows, Linux(Ubuntu)

Issue description

Trying to save a cube map resource using ResourceSave.save() doesn't work.

On Windows a 0 byte .tres file is created and the program crashes

On Linux it creates the resource and doesn't crash but the images aren't on it and will give the following error:

E 0:00:00.942   _write_resource: Resource was not pre cached for the resource section, bug?
  <C++ Error>   Method failed. Returning: "null"
  <C++ Source>  scene/resources/resource_format_text.cpp:1373 @ _write_resource()
  <Stack Trace> Node.gd:17 @ createSkyMat()
                Node.gd:4 @ _ready()

The exact same script WILL work if you set it to a EditorScript and run it using Ctrl+Shift+X.
It will create the resource and work fine.

Steps to reproduce

The attached project uses the following simple script:

extends Node

func _ready():
	createSkyMat()

func createSkyMat():
	
	var top = load("res://icon.png").get_data()
	var bottom = load("res://icon.png").get_data()
	var left = load("res://icon.png").get_data()
	var right = load("res://icon.png").get_data()
	var front = load("res://icon.png").get_data()
	var back = load("res://icon.png").get_data()

	var cubeMap = createCubemap(left,right,top,bottom,front,back)
	
	print(ResourceSaver.save("res://cubemap.tres",cubeMap))
	
	return

func createCubemap(left,right,top,bottom,front,back):
	var cubemap = CubeMap.new()
	cubemap.set_side(0,left)
	cubemap.set_side(1,right)
	cubemap.set_side(2,bottom)
	cubemap.set_side(3,top)
	cubemap.set_side(4,front)
	cubemap.set_side(5,back)
	return cubemap

If you set it to and editor script using the following code and run it with Ctrl+Shift+X it will work correctly.

tool
extends EditorScript

func _run():
	createSkyMat()

func createSkyMat():
	
	var top = load("res://icon.png").get_data()
	var bottom = load("res://icon.png").get_data()
	var left = load("res://icon.png").get_data()
	var right = load("res://icon.png").get_data()
	var front = load("res://icon.png").get_data()
	var back = load("res://icon.png").get_data()

	var cubeMap = createCubemap(left,right,top,bottom,front,back)
	
	print(ResourceSaver.save("res://cubemap.tres",cubeMap))
	
	return

func createCubemap(left,right,top,bottom,front,back):
	var cubemap = CubeMap.new()
	cubemap.set_side(0,left)
	cubemap.set_side(1,right)
	cubemap.set_side(2,bottom)
	cubemap.set_side(3,top)
	cubemap.set_side(4,front)
	cubemap.set_side(5,back)
	return cubemap

Minimal reproduction project

skyboxTest.zip

@clayjohn clayjohn added this to the 3.5 milestone Oct 24, 2021
@clayjohn
Copy link
Member

On RocketChat @lyuma posted that the following commit may resolve this issue V-Sekai@2ba3561

@Ithamar
Copy link

Ithamar commented Sep 12, 2022

This commit also fixes #34312 and a slew of other TextureLayered related tickets that have been open for a long time. Great to see this fixed! 🎊

@Calinou
Copy link
Member

Calinou commented Sep 12, 2022

This commit also fixes #34312 and a slew of other TextureLayered related tickets that have been open for a long time. Great to see this fixed! confetti_ball

I just checked locally and V-Sekai@2ba3561 doesn't apply cleanly on latest master anymore. Do you have a rebased version of that commit? If so, please open a pull request against master 🙂

@Ithamar
Copy link

Ithamar commented Sep 12, 2022

I just checked locally and V-Sekai@2ba3561 doesn't apply cleanly on latest master anymore. Do you have a rebased version of that commit? If so, please open a pull request against master 🙂

I actually tested on 3.x, not on master yet. If it can wait till tomorrow, I can have a look at that.

@Ithamar
Copy link

Ithamar commented Sep 13, 2022

I actually tested on 3.x, not on master yet. If it can wait till tomorrow, I can have a look at that.

@Calinou : I tested this on master, but I think there's more broken for TextureLayered there, won't have time until the weekend to look into that though 😢

@Ithamar
Copy link

Ithamar commented Sep 23, 2022

I've done some investigation but in 4.0beta1 it seems using ResourceSaver.save on any of the TexturedLayered classes is even more broken then in 3.x. I think whoever is responsible for the 4.0 changes needs to sort this out before we can look at fixing the "old" issues....

@Calinou
Copy link
Member

Calinou commented Sep 23, 2022

I've done some investigation but in 4.0beta1 it seems using ResourceSaver.save on any of the TexturedLayered classes is even more broken then in 3.x. I think whoever is responsible for the 4.0 changes needs to sort this out before we can look at fixing the "old" issues....

See #66192 and #65393.

@YuriSizov
Copy link
Contributor

Fixed by #71394.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants