Open musm opened 8 years ago
This can only be a problem when using this interactively, and so I don't think it's too much of an issue. It's something to mention in the README, i.e. "don't do it!", but it shouldn't harm any scripts.
That is a very good point. Yeah it's only possible to do this if used interactively. Still would be nice if there was a way to NULL the ptr or something after the user closes the engine, but it isn't at all obvious how this would be done.
Perhaps @yuyichao has some thoughts.
IIUC these problems are usually solved by keeping a reference count so that the pointer does not become invalid, or having a callback before the pointer becomes invalid. I'm not sure which/any one of these are application given the matlab api.
Segfault under certain user action should be fixed if possible and should be clearly documented if not.
Reproducible with
using MATLAB
julia> show_msession() # close window manually
julia> restart_default_msession()
ERROR: MATLAB.MEngineError("failed to close a MATLAB engine session (err = 1)")
in close(::MATLAB.MSession) at C:\Users\Mus\.julia\v0.5\MATLAB\src\engine.jl:57
in restart_default_msession(::Int64) at C:\Users\Mus\.julia\v0.5\MATLAB\src\engine.jl:69
in restart_default_msession() at C:\Users\Mus\.julia\v0.5\MATLAB\src\engine.jl:67
julia> restart_default_msession()
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0xe2b208d -- engEvalString at C:\Program Files\MATLAB\R2016b\bin\win64\libeng.DLL (unknown line)
while loading no file, in expression starting on line 0
engEvalString at C:\Program Files\MATLAB\R2016b\bin\win64\libeng.DLL (unknown line)
engClose at C:\Program Files\MATLAB\R2016b\bin\win64\libeng.DLL (unknown line)
close at C:\Users\Mus\.julia\v0.5\MATLAB\src\engine.jl:56
unknown function (ip: 00000000152942F6)
jl_call_method_internal at /home/Administrator/buildbot/slave/package_win6_2-x64/build/src/home/Administrator/buildbot/slave/package_win6_2-x64/build/src\julia_internal.h:189 [inlined]
jl_apply_generic at /home/Administrator/buildbot/slave/package_win6_2-x64/build/
having a callback before the pointer becomes invalid. I'm not sure which/any one of these are application given the matlab api.
How would this look like? Ideally I would need to register a callback when the user closes the window.
In this case, I don't think reference counting would work.
ref https://github.com/JuliaInterop/MATLAB.jl/pull/79
The only problematic issue here is if the user closes the matlab engine window manually (i.e. clicking the X button) instead of using the
hide_msession()
function. Because then the pointer to the engine is still attached to a session that does not exist. I'm not sure what is the best way to prevent this from occurring or on how to test if the pointer is still attached to a live engine window; the reason I bring this issue up is that it's possible to segfault julia if you close the window instead ofhide_msession()
.