Git Product home page Git Product logo

Comments (9)

PROMETHIA-27 avatar PROMETHIA-27 commented on July 19, 2024 1

I will note I'm not an expert in that area- I just couldn't find anything that looked wrong.

from rlua.

jugglerchris avatar jugglerchris commented on July 19, 2024 1

Thanks for the report, and especially for the small example! I can reproduce it here.
The fact that there's no unsafe in the example means the bug must be either in rlua or Quat - I'll look into it.

from rlua.

jugglerchris avatar jugglerchris commented on July 19, 2024 1

rlua already uses an allocation function (to track allocation totals), but this doesn't help as userdata is stored internally to Lua with a header which messes up the alignment in this case.

As far as pointers to fields of userdata, it would be difficult to avoid Rust undefined behaviour by e.g. accidentally having an &mut reference at the same time as another reference, for example when calling a method. I think the answer would be the same as if you wanted to keep references to something a different Rust library kept in a Box<T> which it kept ownership of.

However you can implement UserData on Arc<T>, and then you can legally keep another copy of the Arc outside (at the cost of the reference counting and extra indirection of course).

from rlua.

jugglerchris avatar jugglerchris commented on July 19, 2024

Interestingly this happens identically for the Vec4 from glam as well. I think this might something to do with alignment and size of these structures.

This was spot on - it turns out that with the default configuration (LUAI_MAXALIGN) Lua only guarantees 8 byte alignment for userdata. The crash (at least on my x86-64 system) is because Quat::clone() is using the movaps instruction which assumes 16-byte alignment but the Quat is only 8 byte aligned.

I could try to increase LUAI_MAXALIGN, but that would only push the potential problem to the next size up - I think the correct fix will be to compensate in the Lua code where the correct alignment is known.

from rlua.

makspll avatar makspll commented on July 19, 2024

That's very interesting! I noticed there is a possibility to use a custom allocation function, would that be of any use here ?

Also while I have your attention, since the UserData's are stored directly in lua, is it safe to keep and use pointers to fields of UserData managed on the Lua side (say a UserData like MyUserData in this case, but assuming it's alive at that point)

from rlua.

devzf avatar devzf commented on July 19, 2024

@makspll you should try mlua instead, it works fine on your example, no segfault.

from rlua.

jugglerchris avatar jugglerchris commented on July 19, 2024

Hi,
I believe #254 fixes this issue. I will merge it and kick off a release in the next few days if I don't hear otherwise.
Thanks again for the report!

from rlua.

jugglerchris avatar jugglerchris commented on July 19, 2024

I've released rlua 0.19.2 with this fix.

from rlua.

makspll avatar makspll commented on July 19, 2024

Sorry for late response,
This seems to fix my issue! Fantastic work!

from rlua.

Related Issues (20)

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.