Blender crash when translating operator poll message #120759

Open
opened 2024-04-18 02:15:23 +02:00 by Damien Picard · 4 comments
Member

System Information
Operating system: Linux-6.5.0-27-generic-x86_64-with-glibc2.38 64 Bits, X11 UI
Graphics card: NVIDIA GeForce RTX 3060 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 545.29.06

Blender Version
Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-04-17 20:19, hash: 4666af64a6e4
Introduced in 5b9c176b68

Short description of error
When using a translated UI, hovering a disabled button a few times will result in a crash if it displays a poll message.

Exact steps for others to reproduce the error

  • Open the attached blend file and run the script to register an operator with a poll message
  • It appears in the View menu of the text editor
  • Hover it a few times, nothing happens
  • Set the translation to another language
  • Hover the button again, Blender crashes.


So I introduced this crash in 5b9c176b68 but only just discovered it. I’m not sure exactly why the memory gets corrupted, however not freeing the memory fixes the crash:

--- a/source/blender/blenkernel/intern/context.cc
+++ b/source/blender/blenkernel/intern/context.cc
@@ -1036,9 +1036,7 @@ const char *CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
   bContextPollMsgDyn_Params *params = &C->wm.operator_poll_msg_dyn_params;
   if (params->get_fn != nullptr) {
     char *msg = params->get_fn(C, params->user_data);
-    if (msg != nullptr) {
-      *r_free = true;
-    }
+    *r_free = false;
     return msg;
   }

@mont29 Would this be the proper fix?

**System Information** Operating system: Linux-6.5.0-27-generic-x86_64-with-glibc2.38 64 Bits, X11 UI Graphics card: NVIDIA GeForce RTX 3060 Laptop GPU/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 545.29.06 **Blender Version** Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-04-17 20:19, hash: `4666af64a6e4` Introduced in 5b9c176b682c77545126a080c016c0b8b28ed0d5 **Short description of error** When using a translated UI, hovering a disabled button a few times will result in a crash if it displays a poll message. **Exact steps for others to reproduce the error** - Open the [attached blend file](/attachments/0c1dde18-3b0d-4143-a73c-1dc6051d1dc4) and run the script to register an operator with a poll message - It appears in the View menu of the text editor - Hover it a few times, nothing happens - Set the translation to another language - Hover the button again, Blender crashes. <video src="/attachments/52e9b327-ffd5-46ed-8c2b-3d74ee7a991e" title="blender_poll_message_translation_crash_.mp4" controls></video> ----- So I introduced this crash in 5b9c176b682c77545126a080c016c0b8b28ed0d5 but only just discovered it. I’m not sure exactly why the memory gets corrupted, however not freeing the memory fixes the crash: ```diff --- a/source/blender/blenkernel/intern/context.cc +++ b/source/blender/blenkernel/intern/context.cc @@ -1036,9 +1036,7 @@ const char *CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free) bContextPollMsgDyn_Params *params = &C->wm.operator_poll_msg_dyn_params; if (params->get_fn != nullptr) { char *msg = params->get_fn(C, params->user_data); - if (msg != nullptr) { - *r_free = true; - } + *r_free = false; return msg; } ``` @mont29 Would this be the proper fix?
Damien Picard added the
Interest
Translations
Type
Report
Priority
Normal
Status
Needs Triage
labels 2024-04-18 02:15:24 +02:00
Member

Looks like you freed the wrong address:

      disabled_msg = TIP_(CTX_wm_operator_poll_msg_get(C, &disabled_msg_free));

    //....
        
    if (disabled_msg_free) {
      MEM_freeN((void *)disabled_msg);
    }

You should free the return value of CTX_wm_operator_poll_msg_get(C, &disabled_msg_free) not the translated string. 😅

I could make a PR if you want

Looks like you freed the wrong address: ``` disabled_msg = TIP_(CTX_wm_operator_poll_msg_get(C, &disabled_msg_free)); //.... if (disabled_msg_free) { MEM_freeN((void *)disabled_msg); } ``` You should free the return value of `CTX_wm_operator_poll_msg_get(C, &disabled_msg_free)` not the translated string. 😅 I could make a PR if you want
YimingWu added
Status
Confirmed
and removed
Status
Needs Triage
labels 2024-04-18 05:10:02 +02:00
Pratik Borhade added
Priority
High
and removed
Priority
Normal
labels 2024-04-18 06:08:08 +02:00
Member

Crash and regression so raising the priority :)

Crash and regression so raising the priority :)

Indeed, strings from translation system are always static strings that should never be freed.

So in case of a successful translation (i.e. when the result of TIP_(CTX_wm_operator_poll_msg_get(C, &disabled_msg_free)) is not the same as the string returned by CTX_wm_operator_poll_msg_get(C, &disabled_msg_free)), the untranslated string should be freed immediately after its translation (if disabled_msg_free is true!), and disabled_msg_free should be set to false.

Indeed, strings from translation system are always static strings that should never be freed. So in case of a successful translation (i.e. when the result of `TIP_(CTX_wm_operator_poll_msg_get(C, &disabled_msg_free))` is not the same as the string returned by `CTX_wm_operator_poll_msg_get(C, &disabled_msg_free)`), the untranslated string should be freed immediately after its translation (if `disabled_msg_free` is `true`!), and `disabled_msg_free` should be set to `false`.
Bastien Montagne added
Module
User Interface
Type
Bug
and removed
Type
Report
labels 2024-04-18 09:50:27 +02:00
Author
Member

Understood, thank you both.

I could make a PR if you want

@ChengduLittleA I’d appreciate that!

I suspect the translating is not right anyway, since it can potentially happen twice: inside CTX_wm_operator_poll_msg_get() as IFACE_() and in the calling function as TIP_().
It should probably only happen outside the function as TIP_, but there are other calling sites for it, and they should also handle translation.
But if you make a PR I can look at that issue at a later time.

Understood, thank you both. > I could make a PR if you want @ChengduLittleA I’d appreciate that! I suspect the translating is not right anyway, since it can potentially happen twice: inside `CTX_wm_operator_poll_msg_get()` as `IFACE_()` and in the calling function as `TIP_()`. It should probably only happen outside the function as `TIP_`, but there are other calling sites for it, and they should also handle translation. But if you make a PR I can look at that issue at a later time.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#120759
No description provided.