Fix #124165: Python api renaming crash due to uninitialized member #124229

Closed
Pratik Borhade wants to merge 1 commits from PratikPB2123:124165-crash-rename-update into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

asset_params is unintialized until asset browser editor is opened.
In case of this crash, renaming update tries to access params->active_file
but param is nullptr. To avoid the crash use ED_fileselect_ensure_active_params,
it will allocate memory for asset_params if null.

`asset_params` is unintialized until asset browser editor is opened. In case of this crash, renaming update tries to access `params->active_file` but param is nullptr. To avoid the crash use `ED_fileselect_ensure_active_params`, it will allocate memory for asset_params if null.
Pratik Borhade added 1 commit 2024-07-05 13:49:31 +02:00
`asset_params` is unintialized until asset browser editor is opened.
In case of this crash, renaming update tries to access `params->active_file`
but param is nullptr. To avoid the crash use `ED_fileselect_ensure_active_params`,
it will allocate memory for asset_params if null.
Pratik Borhade requested review from Julian Eisel 2024-07-05 13:49:49 +02:00
Pratik Borhade added the
Module
User Interface
label 2024-07-05 13:49:57 +02:00
Author
Member

use of const_cast seems illegal, instead we could remove const from function header :)

use of `const_cast` seems illegal, instead we could remove `const` from function header :)
Member

use of const_cast seems illegal, instead we could remove const from function header :)

Sorry that I have not tested the following, but I think you might be able to move this to the calling site:

diff --git a/source/blender/editors/space_file/space_file.cc b/source/blender/editors/space_file/space_file.cc
index 4f9ee061b8c..91ae506ca0b 100644
--- a/source/blender/editors/space_file/space_file.cc
+++ b/source/blender/editors/space_file/space_file.cc
@@ -393,10 +393,10 @@ static void file_listener(const wmSpaceTypeListenerParams *listener_params)
     case NC_ID: {
       switch (wmn->action) {
         case NA_RENAME: {
+          FileSelectParams *params = ED_fileselect_ensure_active_params(sfile);
           const ID *active_file_id = ED_fileselect_active_asset_get(sfile);
           /* If a renamed ID is active in the file browser, update scrolling to keep it in view. */
           if (active_file_id && (wmn->reference == active_file_id)) {
-            FileSelectParams *params = ED_fileselect_get_active_params(sfile);
             params->rename_id = active_file_id;
             file_params_invoke_rename_postscroll(
                 static_cast<wmWindowManager *>(G_MAIN->wm.first), listener_params->window, sfile);

> use of `const_cast` seems illegal, instead we could remove `const` from function header :) Sorry that I have **not tested** the following, but I _think_ you might be able to move this to the calling site: ```Diff diff --git a/source/blender/editors/space_file/space_file.cc b/source/blender/editors/space_file/space_file.cc index 4f9ee061b8c..91ae506ca0b 100644 --- a/source/blender/editors/space_file/space_file.cc +++ b/source/blender/editors/space_file/space_file.cc @@ -393,10 +393,10 @@ static void file_listener(const wmSpaceTypeListenerParams *listener_params) case NC_ID: { switch (wmn->action) { case NA_RENAME: { + FileSelectParams *params = ED_fileselect_ensure_active_params(sfile); const ID *active_file_id = ED_fileselect_active_asset_get(sfile); /* If a renamed ID is active in the file browser, update scrolling to keep it in view. */ if (active_file_id && (wmn->reference == active_file_id)) { - FileSelectParams *params = ED_fileselect_get_active_params(sfile); params->rename_id = active_file_id; file_params_invoke_rename_postscroll( static_cast<wmWindowManager *>(G_MAIN->wm.first), listener_params->window, sfile); ```
Member

I can't recreate this with main, I think it's fixed with blender/blender@4b168dd645?

But generally, we shouldn't have to create the "params" here, that should only be done in specific places as part of initialization. This is another way to deal with this.

I can't recreate this with `main`, I think it's fixed with blender/blender@4b168dd6453ea? But generally, we shouldn't have to create the "params" here, that should only be done in specific places as part of initialization. [This](https://pablovazquez.art/paste/#XQAAAQB7AwAAAAAAAAAyGkkJwvwRfVDeCk9H2SRoLFgzPWJpxeINRgxFqCtNibsN+okSPLL9RegoUMZLhSeIaiJhw5msk6wms80L1MgM7eDA94A8tyFSlRBAzGvRhVsHf536Oie6twSigeQYgBOFQsJxekmG7Y1+rXsHe0QXgv5rEVIlZKkGA0Ua6PYpzuewLMTZyNUvO4slcpDJw58g1OYKmIO7OhVw97Zujwu6mbXJLqp/YJ6Ew9jwvPcRIDnHcNStdL9p9GY8KApiyFPp+PgvBofd4B7uNmpe3VeBBxd6TgycRUZ8jtVvXCONwnr3hSBUuY0RkFZY/Au3OtciRzAs/eGRicyBl9gGYWMdINxT4Wts+WuX7Bn3YCo/lUdKEclkiwSCsuheqso2WXTi8RLWAUM5l7v7M8ntP3x1bk4qIM/8bm/uRxzjKRKXMw0V7XBYjsfYF/LZCL7ZyZQLd1vOOANtA2EVG/oSR/xR94NZBT/juFqUqp27xFUApGrqMCl1iF8b2enDdFkXSrPMY/M04sNr+dxXEXYQc7pbb5X+CcTTvIcgErFqjGwAWSeuYtm9lfb44cGh+2FIeUfTVugAHd9Wv6Nx15fIINJzOHpoOs/gM7loTDVdjlkz/wWQHAA=) is another way to deal with this.
Member

I can't recreate this with main, I think it's fixed with blender/blender@4b168dd645?

It is!

@PratikPB2123 - It looks like this no longer needed

> I can't recreate this with `main`, I think it's fixed with blender/blender@4b168dd6453ea? It is! @PratikPB2123 - It looks like this no longer needed
Author
Member

Indeed :)

Indeed :)
Pratik Borhade closed this pull request 2024-07-10 12:05:24 +02:00
Pratik Borhade deleted branch 124165-crash-rename-update 2024-07-10 12:05:41 +02:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
3 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#124229
No description provided.