Mantaflow: several crashes due to null pointers. #72894

Closed
opened 2020-01-04 10:08:26 +01:00 by Ray molenkamp · 23 comments
Member

System Information
Operating system: Windows 64 bit
Graphics card: GTX1660

Blender Version
Broken: aad09525fb
Worked: before mantaflow merge

Short description of error
There are several null derefs in the mantaflow code, running a debug build bring them out virtually instantly

the first one is here where obstacles is dereferenced without checking it is a valid pointer, a few lines later, a similar field is checked for null before de-referencing so it's probably needed here as well, however this may be masking the actual issue that the field should not be null in the first place.

When adding the check and trying again it hits another null pointer here where shadow is a null pointer.

Exact steps for others to reproduce the error

  • Make a debug build
  • on the default cube scene use quick smoke
  • Bake
  • poof
**System Information** Operating system: Windows 64 bit Graphics card: GTX1660 **Blender Version** Broken: aad09525fb Worked: before mantaflow merge **Short description of error** There are several null derefs in the mantaflow code, running a debug build bring them out virtually instantly the first one is [here ](https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/intern/fluid.c$1025) where `obstacles` is dereferenced without checking it is a valid pointer, a few lines later, a similar field is checked for null before de-referencing so it's probably needed here as well, however this may be masking the actual issue that the field should not be null in the first place. When adding the check and trying again it hits another null pointer [here ](https://developer.blender.org/diffusion/B/browse/master/source/blender/blenkernel/intern/fluid.c$4025) where `shadow` is a null pointer. **Exact steps for others to reproduce the error** - Make a debug build - on the default cube scene use `quick smoke` - Bake - *poof*
Author
Member

Added subscriber: @LazyDodo

Added subscriber: @LazyDodo
Sebastián Barschkis was assigned by Ray molenkamp 2020-01-04 10:10:21 +01:00
Author
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'

This issue was referenced by adcc9d014c

This issue was referenced by adcc9d014cc2ec27fea74168bdb4c47fddedbeb3

This issue was referenced by 2ff3877f71

This issue was referenced by 2ff3877f71fb0e8c806cdd02825ebdf7d6b8b9cc

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'

@LazyDodo Just pushed an update that gets rid of the entire loop, i.e. the functionality is now directly in Mantaflow. It's much cleaner this way.

Can you check if the issue with the shadow null pointer persists and re-open the task if it does?

@LazyDodo Just pushed an update that gets rid of the entire loop, i.e. the functionality is now directly in Mantaflow. It's much cleaner this way. Can you check if the issue with the `shadow` null pointer persists and re-open the task if it does?
Author
Member

Changed status from 'Resolved' to: 'Confirmed'

Changed status from 'Resolved' to: 'Confirmed'
Author
Member

the obstacles crash is gone, shadow however is still an issue, tested on c27acbcfb7

the obstacles crash is gone, shadow however is still an issue, tested on c27acbcfb7

Was able to reproduce this. Interestingly this bug (i.e. immediate crash with Quick Smoke) only shows up on Windows Debug builds. Still investigating why that is the case. For some reason the grid pointers from Manta don't transfer into Blender.

Was able to reproduce this. Interestingly this bug (i.e. immediate crash with Quick Smoke) only shows up on Windows Debug builds. Still investigating why that is the case. For some reason the grid pointers from Manta don't transfer into Blender.
Author
Member

where should these pointers be transferred? happy to look at it, odd compiler bugs is kinda my jam :)

all looks fine until pyObjectToString where

  PyObject *encoded = PyUnicode_AsUTF8String(inputObject);
  PyObject_Print(encoded, stdout, 0);

still look good

but

  char *result = PyBytes_AsString(encoded);

returns a pointer to valid bufferr, but not containing the data expected.

~~where should these pointers be transferred? happy to look at it, odd compiler bugs is kinda my jam :)~~ all looks fine until `pyObjectToString` where ``` PyObject *encoded = PyUnicode_AsUTF8String(inputObject); PyObject_Print(encoded, stdout, 0); ``` still look good but ``` char *result = PyBytes_AsString(encoded); ``` returns a pointer to valid bufferr, but not containing the data expected.
Author
Member

it's a dangling pointer:

static char *pyObjectToString(PyObject *inputObject)
{
  PyGILState_STATE gilstate = PyGILState_Ensure();

  PyObject *encoded = PyUnicode_AsUTF8String(inputObject); <---- constructs new object
  char *result = PyBytes_AsString(encoded);  <--- gets pointer to data inside this object, does NOT make a copy
  Py_DECREF(encoded); <--- deletes object, python manages the memory, doesn't instantly free it on release builds, but invalidates the buffer contents on debug
  Py_DECREF(inputObject);

  PyGILState_Release(gilstate);
  return result; <-- returns dangling pointer to caller 
}
it's a dangling pointer: ``` static char *pyObjectToString(PyObject *inputObject) { PyGILState_STATE gilstate = PyGILState_Ensure(); PyObject *encoded = PyUnicode_AsUTF8String(inputObject); <---- constructs new object char *result = PyBytes_AsString(encoded); <--- gets pointer to data inside this object, does NOT make a copy Py_DECREF(encoded); <--- deletes object, python manages the memory, doesn't instantly free it on release builds, but invalidates the buffer contents on debug Py_DECREF(inputObject); PyGILState_Release(gilstate); return result; <-- returns dangling pointer to caller } ```

This issue was referenced by c4b5279bbc

This issue was referenced by c4b5279bbca4db2ee88e0451fe6d41175e26719a

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'

@LazyDodo Good catch! Removing the call to Py_DECREF(encoded); should do the trick. Those objects (i.e. manta grid objects, mesh objects, etc.) should really only get deleted via the del calls directly in Python.
My Windows debug build runs fine now, but please reopen if you notice something odd.

@LazyDodo Good catch! Removing the call to `Py_DECREF(encoded);` should do the trick. Those objects (i.e. manta grid objects, mesh objects, etc.) should really only get deleted via the `del` calls directly in Python. My Windows debug build runs fine now, but please reopen if you notice something odd.
Author
Member

I'm pretty sure you just swung in the opposite direction and rather than a danging pointer created a memory leak, PyUnicode_AsUTF8String creates a new object, which you then lose the reference to.

I'm pretty sure you just swung in the opposite direction and rather than a danging pointer created a memory leak, PyUnicode_AsUTF8String creates a new object, which you then lose the reference to.
Author
Member

Changed status from 'Resolved' to: 'Confirmed'

Changed status from 'Resolved' to: 'Confirmed'

@LazyDodo Thoughts on be7571a5e4?

@LazyDodo Thoughts on be7571a5e4?
Author
Member

Added subscriber: @ideasman42

Added subscriber: @ideasman42
Author
Member

That'll do it! The whole chain of pointer->string->pythonobject->string->pointer gives me the heebie jeebies but at-least it appears to be done without causing any leaks/dangling pointers.

although...... that Py_DECREF(inputObject); does look suspicious, why is it there? but i fully admit, python is really not my area of expertise @ideasman42 may have better insights here.

That'll do it! The whole chain of pointer->string->pythonobject->string->pointer gives me the heebie jeebies but at-least it appears to be done without causing any leaks/dangling pointers. although...... that ` Py_DECREF(inputObject);` does look suspicious, why is it there? but i fully admit, python is really not my area of expertise @ideasman42 may have better insights here.

I've added some more clarifications in the comments of ca7bd3f1c3. The Py_DECREF(inputObject); is needed because inputObject is a new reference whose responsibility was handed over.

I've added some more clarifications in the comments of ca7bd3f1c3. The `Py_DECREF(inputObject);` is needed because `inputObject` is a new reference whose responsibility was handed over.
Author
Member

Changed status from 'Confirmed' to: 'Resolved'

Changed status from 'Confirmed' to: 'Resolved'
Author
Member

if you think it's safe, no need to keep this open

if you think it's safe, no need to keep this open

Yes, I think it's safe. Thanks again for helping with this issue!

Yes, I think it's safe. Thanks again for helping with this issue!
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
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#72894
No description provided.