bugGNU Octave - Bugs: bug #67216, Octave on MacOS crashes when...

 
 

bug #67216: Octave on MacOS crashes when displaying large textures

Submitter:  Dmitri A. Sergatskov <dasergatskov>
Submitted:  Fri 13 Jun 2025 05:40:38 PM UTC
   
 
Category:  Plotting with OpenGL Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  None Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Release: 
Operating System:  * Mac OS Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 13 Jun 2025 05:40:38 PM UTC, original submission:  

Currently on MacOS (Apple M4 Pro):

octave:1> a = randn(4097, 8193);
octave:2> imagesc(a)
octave:3> fatal: caught signal fatal: caught signal fatal: caught signal Segmentation fault: 11 -- stopping myself...
Segmentation fault: 11 -- stopping myself...
Segmentation fault: 11 -- stopping myself...
zsh: segmentation fault  octave


Which appears to be due to some limitations/bugs in Apple’s OpenGL driver (or Metal’s OpenGL compatibility layer).

This diff fixes it for me:

diff -r ca1325c84250 libinterp/corefcn/gl-render.cc
--- a/libinterp/corefcn/gl-render.cc    Fri Jun 13 16:02:34 2025 +0200
+++ b/libinterp/corefcn/gl-render.cc    Fri Jun 13 12:58:31 2025 -0400
@@ -4111,6 +4111,23 @@
 #if defined (HAVE_OPENGL)

   const dim_vector& dv = cdata.dims ();
+  #if defined (__APPLE__)
+    // Safety check to prevent OpenGL texture upload crashes on Apple
+    if (dv.ndims () >= 2)
+      {
+        int64_t total_pixels = static_cast<int64_t>(dv(0)) * static_cast<int64_t>(dv(1));
+        static const int64_t MAX_SAFE_PIXELS = 32 * 1024 *1024; // ~33.6M pixels
+        if (total_pixels > MAX_SAFE_PIXELS)
+          {
+            warning ("opengl_renderer::draw_texture_image: image too large (%lldx%lld pixels), "
+                     "skipping render to avoid potential crashes",
+                     static_cast<long long>(dv(1)), static_cast<long long>(dv(0)));
+
+            return;  // Skip rendering
+          }
+      }
+  #endif // __APPLE__
+
   int h = dv(0);
   int w = dv(1);
   double x0, x1, y0, y1;


I understand that Octave’s policy is not to fix vendor’s (driver) bugs, but since on MacOS there is not choice, it is not a driver, but a platform issue.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dasergatskov (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.15-e6e5.
    Corresponding source code