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

[Web] Texture2D.get_image() returns null when running on WebGL #68116

Closed
Henrique-Henrique opened this issue Nov 1, 2022 · 1 comment · Fixed by #68138
Closed

[Web] Texture2D.get_image() returns null when running on WebGL #68116

Henrique-Henrique opened this issue Nov 1, 2022 · 1 comment · Fixed by #68138

Comments

@Henrique-Henrique
Copy link

Godot version

4.0.beta

System information

Windows 10/11, Web

Issue description

get_image() from a Texture2D returns null when running in Web.

The problem was solved in previous versions but returned in version 4

Steps to reproduce

Just get an image from texture from a node in the scene. And play in the browser.

Examples:
$Icon.get_texture().get_image()
get_viewport().get_texture().get_image()

Minimal reproduction project

No response

@akien-mga
Copy link
Member

Confirmed, I had worked around this issue in #65704 for one case which was raising an error in the web editor.

Now the web editor as of 4.0 beta 4 is crashing in this code:

void EditorRunNative::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE: {
			for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
				Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i);
				if (eep.is_null()) {
					continue;
				}
				Ref<ImageTexture> icon = eep->get_run_icon();
				if (!icon.is_null()) {
					Ref<Image> im = icon->get_image();
					im = im->duplicate();
					im->clear_mipmaps();
					if (!im->is_empty()) {
						im->resize(16 * EDSCALE, 16 * EDSCALE);
						Ref<ImageTexture> small_icon = ImageTexture::create_from_image(im);
						MenuButton *mb = memnew(MenuButton);
						mb->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::run_native).bind(i));
						mb->connect("pressed", callable_mp(this, &EditorRunNative::run_native).bind(-1, i));
						mb->set_icon(small_icon);
						add_child(mb);
						menus[i] = mb;
					}
				}
			}
		} break;

Because there's no null check before im->duplicate().

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

Successfully merging a pull request may close this issue.

4 participants