# Reproducable FileDialog crashes on Win

**URL:** <https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300>\
**Category:** wxRuby\
**Created:** [August 4, 2011, 1:16pm UTC](https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300 "2011-08-04T13:16:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 4, 2011, 1:16pm UTC](https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300/1 "2011-08-04T13:16:57Z")

</div>

Hi all,

I’m seeing reproducable crashes in my wxruby application under  
circumstances:

The application runs a WxGrid backed with my own subclass of TableBase.  
The application works fine. Trying to open a FileDialog I get a crash on  
Windows ONLY. There is no crash report, no segfault message, the  
application simply quits at the call to FileDialog#show\_modal

Here is something that I hope raises someone’s suspicion: The crash  
happens ALWAYS after I scrolled through the WxGrid using a mouse wheel.  
I do not handle mousewheel events in the grid. The crash NEVER happens  
if I do not scroll through the grid before calling to open the  
FileDialog, everything works just fine.

Looking at the windows event viewer, I find the following log:

Faulting application name: ruby.exe, version: 1.8.7.0, time stamp:  
0x4c698044  
Faulting module name: ntdll.dll, version: 6.1.7601.17514, time stamp:  
0x4ce7ba58  
Exception code: 0xc0000374  
Fault offset: 0x000ce653  
Faulting process id: 0xb10  
Faulting application start time: 0x01cc52945f2fb020  
Faulting application path: C:\Ruby187\bin\ruby.exe  
Faulting module path: C:\Windows\SysWOW64\ntdll.dll

I’m using wxruby 2.0.1 x86-mingw32 and wxwidgets 2.8.11 running on  
Windows 7 Ultimate x64.

Thanks for any help,  
Tony

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [August 4, 2011, 2:17pm UTC](https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300/2 "2011-08-04T14:17:22Z")

</div>

the really funky part is that I can replace the GridTableBase by a  
minimum/non functional implementation (see below) and the crash will  
still happen. However, when I use the built-in table (Grid#create\_grid)  
the FileDialog will always open just fine.

I also verified the crash with wxWidgets 2.8.12. On the other hand, the  
code runs fine on OSX 10.6.

* * *

class ValueGrid \< Wx::GridTableBase

def initialize foo, data  
super()  
@rows = data.size  
end

def get\_number\_cols  
2  
end

def get\_number\_rows  
@rows  
end

def get\_value row, col  
“foobar”  
end

def is\_empty\_cell row, col  
false  
end

def get\_attr row, col, kind  
Wx::GridCellAttr.new Wx::BLACK, Wx::WHITE, Wx::NULL\_FONT,  
Wx::ALIGN\_LEFT, Wx::ALIGN\_TOP  
end

end

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [August 12, 2011, 8:57am UTC](https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300/3 "2011-08-12T08:57:02Z")

</div>

Update:

the crash seems to be connected to background threads. One background  
thread is listening on a serial interface (using hparra’s serialport). A  
timer triggers a call to Thread.pass() every couple of milliseconds.  
When I kill the serial reception in the background, the crash seems to  
disappear.

So the question becomes: how can I open a file dialog with a background  
thread running, that accesses the serial interface?

Thanks,  
T

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [September 13, 2011, 12:06am UTC](https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300/4 "2011-09-13T00:06:53Z")

</div>

Hey Mario,

appreciate your answer. I’m well aware of green vs. native threads. Of  
course I tried blocking the worker threads, just that isn’t always easy  
when you’re communicating with outboard equipment as I do.

Plus: A file dialog shouldn’t really cause any access to shared  
variables either.

I tried switching to 1.9 (after I spent a while getting it to run) but  
the result was pretty much the same.

It’s sad, having spent over a year into this. But I’m giving up. Some  
(hopefully constructive) feedback on my collected experiences will  
follow in another thread.

Thanks again for taking your time to answer me.

T

---

<div class="post-metadata">

**Author:** ![tony44](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dc4da7/32.png) [@tony44](https://www.ruby-forum.com/u/tony44)\
**Post date:** [August 12, 2011, 9:12am UTC](https://www.ruby-forum.com/t/reproducable-filedialog-crashes-on-win/210300/5 "2011-08-12T09:12:52Z")

</div>

Hello Tony,

This sounds very much like a Re-entry kind of lockup, that occurs when  
trying to use more then one thread, in the Ruby Interpreter. And from  
the  
crashes, it very much looks like your running 1.8 line of the Ruby  
Interpreter. With that being the case, the 1.8 line, uses Software  
based  
Threads, or Faux threads. Meaning, that there is no secondary thread  
actually created on the Operating System, but instead is handled  
internally  
by the interpreter itself. We also call them Green Threads. Which is  
always an issue when it comes to Re-entry based code being executed.  
What  
is basically happening, is that when you run with Green Threads, the  
interpreter creates a stack for each green thread, that all runs on the  
Same  
Operating System thread. When the background thread is called, and some  
GUI  
Function is currently being ran (Such as a GUI Dialog, or population of  
a  
wxGrid), the program will crash, trying to handle this, cause a re-entry  
clause occurred when trying to execute the function, or rather, the  
method  
in question.

The main thing that causes these re-entry errors, is trying to access a  
variable used between two different threads. Which is never a good  
thing.  
The only suggestion that I can make, is that when the GUI needs  
priority  
over the background worker threads, suspend the worker threads for the  
duration of the GUI execution. In other words, when showing a File  
Dialog,  
suspend the worker threads, show the dialog, once you get a response,  
and  
you can process the info in Ruby again, resume the Worker threads, then  
continue with processing the data.

The other option, which isn’t much of an option, is to use the Ruby 1.9  
line  
of interpreter, as it uses Native OS Threads for Ruby Threads. But you  
will  
still need to be careful of worker threads, and GUI threads, just not  
as insanely.

hth,

Mario
