Coder Social home page Coder Social logo

unexpected crashes about mex.jl HOT 6 OPEN

maartenvd avatar maartenvd commented on July 20, 2024
unexpected crashes

from mex.jl.

Comments (6)

taylormcd avatar taylormcd commented on July 20, 2024

I've also had occasionally crashing when using the call_matlab function. I don't know if this is occurs due to a limitation imposed on MEX files by MATLAB or due to improper data handling on the Julia side and I haven't been able to pinpoint the root cause of this issue. For not being very large, this package is quite complicated since it deals with two higher level languages and their respective lower level interfaces. I've often thought it would be nice to have someone who is an expert in MEX files and/or embedding Julia take a look at this package. I don't consider myself to be an expert in either.

As a workaround, try to replace all instances of call_matlab with equivalent calls to MATLAB using MATLAB.jl. The downside of this approach is that it limits the code you can call to what is available to the MATLAB engine session created by MATLAB.jl. Hopefully this works for your application.

from mex.jl.

maartenvd avatar maartenvd commented on July 20, 2024

Well the attached project is primarily a test on the stability of mex.jl, on a fork that was made quite a while ago. Honestly if the issue is only in the call_matlab function, then everything I really need for my actual purposes already works! I will experiment a bit with some tests that do not work with call_matlab.

Though if the issue is really only there, and probably being a GC issue - seeing how sporadic the crashes are - I can even try to create a minimal working(crashing) example. I won't have time for the coming 3 weeks, but if I have anything I will try to propose a fix or at the very least post it somewhere hereabouts!

In any case thanks a lot for updates to this package!

from mex.jl.

maartenvd avatar maartenvd commented on July 20, 2024

ok the easiest crash I can find is:

jl.eval('invalidsyntax()')
jl.eval('GC.gc()')

this is perhaps not very important, but pretty much any error you make in julia will later on lead to an unexpected crash when garbage collection triggers.

A totally unrelated minimal example is this:

function test(args::Vector{MATLAB.MxArray})
    out = jvalue(args[3])
    temp = args[2];
    for i in 1:out
        temp = call_matlab(1,"feval",[args[1],temp])
        GC.gc()
    end
    
    temp
end

jl.mex('test',@(x) x*x,rand(5),1)

will run without any problems, even when called multiple times. However this

jl.mex('test',@(x) x*x,rand(5),2)

immediately comes crumbling to the ground.

from mex.jl.

taylormcd avatar taylormcd commented on July 20, 2024

from mex.jl.

maartenvd avatar maartenvd commented on July 20, 2024

I feel rather silly, as the second example is actually also an error.

temp = call_matlab(1,"feval",[args[1],temp])

call_matlab will return a vector, which gets put into temp. temp then gets again given to call_matlab, which is where it goes wrong.

it should've been

temp = call_matlab(1,"feval",[args[1],temp])[1]

which works just fine?

So then, it mostly seems that julia errors in mexed calls or matlab errors in callbacks will lead to some invalid memory somewhere and then crashes later on.

from mex.jl.

taylormcd avatar taylormcd commented on July 20, 2024

I tried to dig into this, but can't figure out where the issue is. It seems to just affect the call_matlab function though. The simplest example I can find is

jleval call_matlab(1, "sin", 1.0)

Note that this function doesn't error, but this does cause a segmentation fault when MATLAB is closed (which can be seen if MATLAB is run from the terminal). Unfortunately, I don't really have the time to look into this any further.

from mex.jl.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.