Sublime Forum

GC view making ST unexpectedly crash

#1

I’ve been trying to debug this issue for few minutes and when I thought I had “fixed” it’s hitting me back again. Here’s the thing, I’m keeping Sublime.view instances into the global variable quick_panels_cache and at certain point when the view is closed i want to remove it from the dictionary.

Minimal code would be this:

def on_done(self, panel, action):
    view = panel['view']
    done = panel['done']
    content = view.substr(sublime.Region(0, view.size()))

    view_name = view.name()
    self.close_view(view)
    del quick_panels_cache[view_name]

    if action == 'close':
        return

    if done:
        done(content)

def close_view(self, view):
    window = self.window
    window.focus_view(view)
    view.set_scratch(True)
    window.run_command("close_file")

Thing is, it doesn’t matter which order of lines I use, this one:

    self.close_view(view)
    del quick_panels_cache[view_name]

or this one:

    del quick_panels_cache[view_name] 
    self.close_view(view)

The result will be that sometimes Sublime Text (non-deterministic) will abort unexpectedly without giving any traceback nor warning and the only clues will be just putting some .dmp files on the root folder.

I guess this is happening because no matter the order of lines, at certain point the view instance isn’t available anymore (because of GC and the fact than self.close_view is asynchronous) and the sublime_api commands are assuming the view instance to be present as a precondition, that’s my assumption…

Trying to think a good fix of this one but the only i can think of is not removing the view instance from my global cache… but that’s not a good solution at all, so… you got any better one?

Btw, the main reason why I’m using this global cache, apart of storing some bounded methods is because it seems you can’t use non-json serializable objects with view.run_command)… Probably there is a better way of doing this though.

Thanks in advance.

0 Likes

#2

Btw, another reason why I’m using this global cache with views + bounded methods is because I couldn’t attach bounded methods to a view, If I recall correctly I had tried setattr with a sublime.view but when i find the view again the attr is not there anymore. I guess views are cloned over and over and they’re not singleton objects… Anyone knows whether this could be done? ie: attaching extra data/methods to a particular view?

0 Likes