Skip to content

Implement TextServer GDExtension interface, remove TextServer GDNative interface. - #52192

Merged
akien-mga merged 1 commit into
godotengine:masterfrom
bruvzg:text_server_gdext
Oct 1, 2021
Merged

akien-mga merged 1 commit into
godotengine:masterfrom
bruvzg:text_server_gdext

Conversation

@bruvzg

@bruvzg bruvzg commented Aug 28, 2021

Copy link
Copy Markdown
Member

Implement TextServer GDExtension interface, remove TextServer GDNative interface.

@bruvzg bruvzg added this to the 4.0 milestone Aug 28, 2021
@bruvzg
bruvzg force-pushed the text_server_gdext branch 6 times, most recently from 5944be9 to bbbdf40 Compare August 30, 2021 10:12
@bruvzg

bruvzg commented Aug 30, 2021 •

Copy link
Copy Markdown
Member Author

Right now, using the following code to register text server from the extension fails to compile do to missing Ref(const Ref<T_Other>) constructor in the godot-cpp, casting a raw pointer to TextServer * and creating Ref from it result in a broken class which cannot call virtual methods from the extension. I'm not sure what's the correct way to do it:

void register_types() {
	ClassDB::register_class<TextServerTest>();
	if (TextServerManager::get_singleton()) {
		Ref<TextServerTest> ts;
		ts.instantiate();
		TextServerManager::get_singleton()->add_interface(ts);
	}
}

Creating and adding gdextension text server from the gdscritt works fine. But it's too late to be usable, TextServer should be created and selected as primary before initializing font resources and default theme.

More issues with godot-cpp - godotengine/godot-cpp#602 (comment)

@bruvzg
bruvzg force-pushed the text_server_gdext branch 2 times, most recently from 14d7526 to 303ebb2 Compare August 30, 2021 11:07
@bruvzg
bruvzg force-pushed the text_server_gdext branch 2 times, most recently from f680060 to b1aabf1 Compare August 31, 2021 08:35
@bruvzg
bruvzg marked this pull request as ready for review August 31, 2021 09:58
@bruvzg
bruvzg requested review from a team as code owners August 31, 2021 09:58
@bruvzg

bruvzg commented Aug 31, 2021

Copy link
Copy Markdown
Member Author

With the current godot-cpp issues, I can't fully test server implantation, but the engine changes should be good to go.

Comment thread doc/classes/TextServerAdvanced.xml Resolved
Comment thread main/main.cpp Resolved
Comment thread platform/osx/os_osx.mm Resolved
Comment thread platform/osx/os_osx.mm Resolved
@bruvzg

bruvzg commented Sep 28, 2021

Copy link
Copy Markdown
Member Author

Updated to the current godot-cpp, now it seems to be able to create and register the module (and can call some basic interface function like get_name), but there are still issues:


Ref<Something> arguments/returns do not work, engine builds, module do not.

	GDVIRTUAL4(_font_set_texture_image, RID, const Vector2i &, int, const Ref<Image> &);
	GDVIRTUAL3RC(Ref<Image>, _font_get_texture_image, RID, const Vector2i &, int);

GDNativePtr<Something> arguments/returns do not work, engine builds with arguments, nothing builds with returns.

	GDVIRTUAL1RC(GDNativePtr<const Glyph>, _shaped_text_get_glyphs, RID);
	GDVIRTUAL3C(_shaped_text_get_carets, RID, int, GDNativePtr<CaretInfo>);

Removing interface seems to be crashing (Interface destructor is never called), maybe TextServerManager is destroyed too late:

Exception Type:        EXC_BAD_ACCESS (SIGABRT)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000100000008
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x100000008:
--> 
    __TEXT                      102af8000-109ec4000    [115.8M] r-x/r-x SM=COW  /Users/*/*.arm64

Application Specific Information:
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x000000018044ce68 __pthread_kill + 8
1   libsystem_pthread.dylib       	0x000000018047f43c pthread_kill + 292
2   libsystem_c.dylib             	0x00000001803c7454 abort + 124
3   godot.osx.tools.arm64         	0x0000000102e8d1a0 handle_crash(int) + 2152 (crash_handler_osx.mm:163)
4   libsystem_platform.dylib      	0x00000001804cac44 _sigtramp + 56
5   godot.osx.tools.arm64         	0x00000001074e9d0c RefCounted::unreference() + 264 (ref_counted.cpp:85)
6   godot.osx.tools.arm64         	0x0000000102edb8a4 Ref<TextServer>::unref() + 44 (ref_counted.h:220)
7   godot.osx.tools.arm64         	0x0000000102edb864 Ref<TextServer>::~Ref() + 28 (ref_counted.h:233)
8   godot.osx.tools.arm64         	0x0000000102ec69cc Ref<TextServer>::~Ref() + 28 (ref_counted.h:232)
9   godot.osx.tools.arm64         	0x0000000106855b14 CowData<Ref<TextServer> >::_unref(void*) + 156 (cowdata.h:218)
10  godot.osx.tools.arm64         	0x00000001068556c4 CowData<Ref<TextServer> >::resize(int) + 148 (cowdata.h:276)
11  godot.osx.tools.arm64         	0x0000000106856128 CowData<Ref<TextServer> >::remove(int) + 300 (cowdata.h:178)
12  godot.osx.tools.arm64         	0x000000010683e4f8 Vector<Ref<TextServer> >::remove(int) + 36 (vector.h:70)
13  godot.osx.tools.arm64         	0x000000010683e770 TextServerManager::~TextServerManager() + 192 (text_server.cpp:148)
14  godot.osx.tools.arm64         	0x000000010683e82c TextServerManager::~TextServerManager() + 28 (text_server.cpp:143)
15  godot.osx.tools.arm64         	0x0000000102ec6b60 void memdelete<TextServerManager>(TextServerManager*) + 48 (memory.h:109)
16  godot.osx.tools.arm64         	0x0000000102ed9b00 Main::cleanup(bool) + 648 (main.cpp:2757)
17  godot.osx.tools.arm64         	0x0000000102ebe994 main + 844 (godot_main_osx.mm:81)
18  libdyld.dylib                 	0x000000018049d430 start + 4

@bruvzg
bruvzg force-pushed the text_server_gdext branch 2 times, most recently from d5ff81c to 5ad443a Compare September 28, 2021 11:36
@bruvzg

bruvzg commented Sep 28, 2021

Copy link
Copy Markdown
Member Author

Removing interface seems to be crashing (Interface destructor is never called)

Crash seems to be completely random, sometimes it's working OK (and it seems to always work when running under debugger), probably something in the extension API is uninitialized.

@bruvzg

bruvzg commented Sep 28, 2021 •

Copy link
Copy Markdown
Member Author

Relevant issues:
godotengine/godot-cpp#628 solved
godotengine/godot-cpp#629
godotengine/godot-cpp#630 solved, with a few workarounds
godotengine/godot-cpp#633

@bruvzg
bruvzg force-pushed the text_server_gdext branch 2 times, most recently from 9431f42 to 08ba119 Compare September 30, 2021 08:40
@bruvzg
bruvzg marked this pull request as ready for review September 30, 2021 10:04
@bruvzg
bruvzg requested a review from a team as a code owner September 30, 2021 10:04
@bruvzg
bruvzg force-pushed the text_server_gdext branch 2 times, most recently from fe92682 to 59b083b Compare October 1, 2021 08:59
Comment thread core/variant/native_ptr.h Resolved
@bruvzg
bruvzg force-pushed the text_server_gdext branch from 59b083b to 0c0b5c8 Compare October 1, 2021 12:15
Comment on lines +853 to +868
// TextServer structures
{
Dictionary d;
d["name"] = "Glyph";
d["format"] = "int start,int end,uint8_t count,uint8_t repeat,uint16_t flags,float x_off,float y_off,float advance,RID font_rid,int font_size,int32_t index";

native_structures.push_back(d);
}
{
Dictionary d;
d["name"] = "CaretInfo";
d["format"] = "Rect2 leading_caret,Rect2 trailing_caret,TextServer::Direction leading_direction,TextServer::Direction trailing_direction";

native_structures.push_back(d);
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should eventually move these definitions to the text server header as well, no sure how exactly. And do the same for AudioFrame and GDVIRTUAL_NATIVE_PTR(AudioFrame)

@akien-mga
akien-mga merged commit 928c002 into godotengine:master Oct 1, 2021
@akien-mga

Copy link
Copy Markdown
Member

Thanks!

@bruvzg
bruvzg deleted the text_server_gdext branch October 1, 2021 13:32
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
BendyLand pushed a commit to BendyLand/voltaire that referenced this pull request Aug 2, 2026
wangshucheng pushed a commit to wangshucheng/godot that referenced this pull request Aug 27, 2026
Shane-Gadsby pushed a commit to Shane-Gadsby/godotwebgpu that referenced this pull request Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants