Page MenuHome

Fix: Socket tooltip display error
ClosedPublic

Authored by Ethan Hall (Ethan1080) on Apr 26 2022, 6:55 AM.

Details

Summary

For certain socket types, such as object or material, the name of the
item is not obtained correctly leading the tooltip to display random
non-character memory values as text.

This patch fixes the bug with minimal changes.

Bug introduced in: rB47276b847017

Diff Detail

Repository
rB Blender
Branch
fix_socket_names (branched from master)
Build Status
Buildable 21866
Build 21866: arc lint + arc unit

Event Timeline

Ethan Hall (Ethan1080) requested review of this revision.Apr 26 2022, 6:55 AM
Ethan Hall (Ethan1080) created this revision.

I don't understand why using ->next is correct here, how does that make sense?

I don't understand why using ->next is correct here, how does that make sense?

Before the commit, it worked like this:

id_to_inspection_string((ID *)*value.get<Object *>(), ID_OB);

After the commit, it works like this:

const void *buffer = value.get();
id_to_inspection_string((ID *)buffer, ID_OB);

Which is equivalent this:

id_to_inspection_string((ID *)value.get<Object *>(), ID_OB);

Notice the sneaky dereference in the original is lost.


This patch, works like this:

const void *buffer = value.get();
id_to_inspection_string((ID *)((ID *)buffer)->next, ID_OB);

Which is equivalent to the original.


Either that, or I don't know what I am talking about.

Hmm, I don't think ->next is the same as de-referencing the ID pointer. I don't think the next and previous pointers are expected to be valid for IDs outside of Main.

What about this? *static_cast<ID **>(buffer)

@Hans Goudey (HooglyBoogly)

Hmm, I don't think ->next is the same as de-referencing the ID pointer. I don't think the next and previous pointers are expected to be valid for IDs outside of Main.

ID is defined like this.

/* There's a nasty circular dependency here.... 'void *' to the rescue! I
 * really wonder why this is needed. */
typedef struct ID {
  void *next, *prev;
  struct ID *newid;

  struct Library *lib;
⋮

*next is first in the struct, so the deref gets that pointer and then casts it to ID *.

What about this? *static_cast<ID **>(buffer)

Does not work.

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2440	'static_cast': cannot convert from 'const void *' to 'ID **'	bf_editor_space_node	C:\Users\Ethan\Documents\blender-git\blender\source\blender\editors\space_node\node_draw.cc	790
Ethan Hall (Ethan1080) planned changes to this revision.Apr 26 2022, 7:55 PM

@Hans Goudey (HooglyBoogly) This works: (ID *)*(static_cast<const Object *const *>(buffer))

Note: This patch does not fix the name update issue for collections. (When a collection is renamed, the old name is still displayed in the socket. Problem since 3.0.0)

I haven't posted a bug report on it yet because this bug covers it up, and I only found the bug while testing this patch.

Looks better now! I think it could be a little simpler though if we removed the second cast to ID * and used static_cast to make a const ID ** in the first place. That would review id_to_inspection_string to have a const ID * argument, which seems fine.

This revision is now accepted and ready to land.Apr 28 2022, 8:59 PM