Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

SetFieldT fails on string pointer #7307

Unanswered
marstaik asked this question in Q&A
Discussion options

Hi, I am trying to generate a reflection-based ui so I can edit flatbuffers. I don't care if the performance isnt ideal when im BUILDING them in this case, as its a GUI tool, and I understand as strings and other optional tables are added by the user, that the underlying vector has to be resized.

Ive gone through ReflectionTest in test.cpp, and am using a resizing vector with a PIV just like the test.
I can set a struct member just fine, but I cant set an optional string, even with the AddFlatBuffer function.

It goes something like this:

	virtual void text_changed( const String& p_str ) override
	{
		// fb
		// "fb" is simply a wrapper object that holds a vector data, and the "piv" to the root inside of it
		// it can be coerced to both Table* and Table* via operator() casts for ease of use
		const flatbuffers::String* str = flatbuffers::GetFieldS( *fb, *field );
		// There's already a string in the table, modify it
		if ( str ) {
			flatbuffers::SetString(
				*schema,
				std::string( p_str.ascii() ),
				flatbuffers::GetFieldS( *fb, *field ),
				&fb->data );
			
			print_line("MODIFIED FB STRING");
			return;
		}
		// we need to add a new one
		flatbuffers::FlatBufferBuilder s_fbb;
		s_fbb.Finish( s_fbb.CreateString( (const char*)p_str.ascii() ) );
		auto string_ptr = flatbuffers::AddFlatBuffer( fb->data, s_fbb.GetBufferPointer(), s_fbb.GetSize() );
		
		bool ret_val = flatbuffers::SetFieldT( *fb, *field, string_ptr );
		
		print_line("ADDED FB STRING");
	}

In this case, ret_val is always false. It seems to fail in SetFieldT >>> table->SetPointer() >>> GetOptionalFieldOffset(field) which returns 0, causing it to fail.

I notice the test example uses a vector of strings, and manually resizes the vector to add in a new string offset, which is different. I do not see a test case that simply adds in a string by itself.

Is there a different way of doing this? Or is it a bug?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /