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

draw_string() only renders blocks and throw thousands of errors #15023

Closed
1 task done
leoddd opened this issue Dec 25, 2017 · 10 comments
Closed
1 task done

draw_string() only renders blocks and throw thousands of errors #15023

leoddd opened this issue Dec 25, 2017 · 10 comments

Comments

@leoddd
Copy link
Contributor

leoddd commented Dec 25, 2017

Godot version:

Godot 3 e1da261

OS/device including version:

Ubuntu 16.04, Radeon HD 6450

Issue description:

When using draw_string() within _draw(), Godot draws rectangles the width and height of the letters it should be drawing instead of the actual letters. for both Dynamic and Bitmap fonts.
They always display fine inside a Label. BitmapFont seems to render fine in-game, but retains the block issue when used in-editor in a tool script, while DynamicFont has the same issue in-game.

While it draws the rectangles, it outputs thousands of copies of this error to the error log:

core/rid.h:164 - Condition ' !id_map.has(p_rid.get_data()) ' is true. returned: __null

This is how a drawn string looks:
image

Steps to reproduce:
Try using draw_string() in any CanvasItem's _draw() method. Reproduction project is attached.

Example code:

	var font = DynamicFont.new()
	var data = DynamicFontData.new()
	data.font_path = "res://fonts/freepixel.ttf"
	font.font_data = data
	font.size = 16
	draw_string(font, Vector2(), "Test", Color("FFFFFF"))

Minimal reproduction project:

MinimalTTF.zip

  • I searched the existing GitHub issues for potential duplicates.
@ghost ghost added this to the 3.0 milestone Dec 25, 2017
@volzhs
Copy link
Contributor

volzhs commented Dec 25, 2017

var font = DynamicFont.new()

func _ready():
	var data = DynamicFontData.new()
	data.font_path = "res://freepixel.ttf"
	font.font_data = data
	font.size = 17

func _draw():
	draw_string(font, Vector2(5, font.get_height()+5), get_name(), Color("000000"))
	draw_string(font, Vector2(4, font.get_height()+4), get_name(), Color("FFFFFF"))

this will fix your problem.
I'm not sure but you can't probably create a resource in _draw
at least, it's not efficient to create new DynamicFont and DynamicFontData at every _draw call.

@volzhs
Copy link
Contributor

volzhs commented Dec 25, 2017

I'm not sure if it's a bug.

@leoddd
Copy link
Contributor Author

leoddd commented Dec 25, 2017

I see, thanks! Strange limitation but it'll have its reasons, anyone know if it's mentioned in any docs?

@reduz
Copy link
Member

reduz commented Dec 26, 2017

well, this could technically be fixed by forcing to update cache if a char is requested, but usage is definitely not optimal at all..

@reduz
Copy link
Member

reduz commented Dec 26, 2017

no, nevermind, this is not a bug. you are deleting the font after using it, this is why you see those white recangles.

@reduz reduz closed this as completed Dec 26, 2017
@ghost ghost added archived and removed bug confirmed labels Dec 26, 2017
@leoddd
Copy link
Contributor Author

leoddd commented Dec 27, 2017

That makes a lot more sense than an arbitrary restriction on resource creation during draw.
I always figured that calling draw
* methods inside _draw() made the drawing happen immediately, meaning it would be fine to use temporary resources, but this is fine now that I'm aware.

@ArthaTi
Copy link

ArthaTi commented Aug 26, 2019

Well, I think this could at least get a more meaningful error message. I had no idea what it means when I got it.

@wajrou
Copy link

wajrou commented Aug 26, 2022

I get these errors when I put Label (2D) under Viewport (in 3D scene as TextureViewport in Sprite3D). The strange thing is font is working (from Project Settings theme)... until window is resized, maximized or switched to fullscreen. After that font in Labels is forgotten? And drawn strangely, filled rectangles or some font fragments, and debugger is full of these errors.

Thanks to @reduz I just put my default theme/font into Labels under Viewport and everything is working without errors even after resizing the window.

Godot 3.5.stable on Linux

@Calinou
Copy link
Member

Calinou commented Aug 26, 2022

I get these errors when I put Label (2D) under Viewport (in 3D scene as TextureViewport in Sprite3D). The strange thing is font is working (from Project Settings theme)... until window is resized, maximized or switched to fullscreen. After that font in Labels is forgotten? And drawn strangely, filled rectangles or some font fragments, and debugger is full of these errors.

This is likely a bug caused by font oversampling, which you can disable in the Project Settings as a workaround.

@DevViktorKovacs
Copy link

Well, I think this could at least get a more meaningful error message. I had no idea what it means when I got it.

Exactly, every time the engine dosen't produce a meaningful feedback, it's by definition is a bug. It's a null reference exception stemming from the source of the engine, that doesn't indicate doesn't point towards the actual root of the problem...

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

7 participants