amirrajan / rubymotion-applied

RubyMotion documentation provided by the community. Submit a pull request to the docs for a free one year indie subscription.
Apache License 2.0
49 stars 9 forks source link

Crash when call-ing proc stored as accessor in UIDocument subclass #89

Open hboon opened 6 years ago

hboon commented 6 years ago

I have a UIDocument subclass in which I have added an accessor for storing a proc. When the proc gets call-ed, it crashes consistently. I have another similar accessor storing another proc in this same subclass and it doesn't crash. The difference is that the crashing proc gets called when the UIDocument's documentState property is UIDocumentStateClosed.

Code snippet below:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000a13dcbeb0
VM Region Info: 0xa13dcbeb0 is not in any region.  Bytes after previous region: 35229843121  
      REGION TYPE                      START - END             [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_NANO (reserved) 00000001d8000000-00000001e0000000 [128.0M] rw-/rwx SM=NUL  ...(unallocated)
--->  
      UNUSED SPACE AT END

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [0]
Triggered by Thread:  0

Filtered syslog:
None found

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libobjc.A.dylib                 0x0000000182f3b61c class_getSuperclass + 4
1   Mimic                           0x0000000102896710 rb_objc_set_type + 124
2   Mimic                           0x000000010295f728 ivar_get + 292
3   Mimic                           0x0000000102840858 vm_ivar_get + 408
4   Mimic                           0x000000010284f2d0 rb_scope__mockup_document=:__block__.23 + 5403344 (editor_screen.rb:384)
5   Mimic                           0x0000000102988164 vm_block_eval+ 6685028 (RoxorVM*, rb_vm_block*, objc_selector*, unsigned long, int, unsigned long const*) + 1288
6   Mimic                           0x00000001029860b8 rb_vm_dispatch + 3608
7   Mimic                           0x00000001026bd86c vm_dispatch + 1048
8   Mimic                           0x00000001026c3aa4 rb_scope__document_changed:__ + 3783332 (app_document.rb:117)
module Mockup
  class AppDocument < UIDocument
    block_attr_accessor :on_document_progress_available_block
  end
end

class Class
  def block_attr_accessor(*my_accessors)
    my_accessors.each do |accessor|
      define_method(accessor) do
        instance_variable_get("@#{accessor}")
      end

      define_method("#{accessor}=") do |accessor_value|
        instance_variable_set("@#{accessor}", accessor_value ? accessor_value.weak! : nil)
      end
    end
  end
end

@doc.on_document_progress_available_block = proc {
  #If I have any code in the proc, it crashes
}

This triggers the crash:

doc&on_document_progress_available_block.call #This is invoked when `documentState` == `UIDocumentStateClosed `
amirrajan commented 6 years ago

Is this only an occasional annoyance or is it severely hindering your work?

hboon commented 6 years ago

It was a showstopper until I realised that I can workaround it by not invoking the proc when documentState == UIDocumentStateClosed. So it appears to not bother me for now.

amirrajan commented 6 years ago

On the list (thanks for a consistent way to recreate).