Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:14:54+00:00 2026-06-18T03:14:54+00:00

Is it possible that luabind checks, if a member function call to an exported

  • 0

Is it possible that luabind checks, if a member function call to an exported class (object) is for a valid object?

lets assume that i have a Class called Actor exposed using luabind to lua. Im calling a lua function from C++ with an actor object as parameter. Now before the function finishes, a script write would put the actor object in a global lua reference to be accessed later.

Later on, the actor object is deleted from the C++ site, another function is called which tries to access the invalidated actor object (any method from it) – and obviously since it has been deleted, it results in a crash (access violation)

sample:

local myObjRef = nil

function doSomethingWithActor(actor)
 -- save, still valid object
 actor:Say("hello")
 myObjRef = actor
end

function calledAfterActorWasDeleted()
  --- will crash if the c++ object has been deleted meanwhile, works fine if it still exists
  myObjRef:Say("Crash...")
end

A NIL check doesnt help here, is this something that can be checked on luabinds site? The functions are executed using lua_pcall(….) and the stacktrace shows the error at luabinds call.hpp results = maybe_yield(L, lua_gettop(L) – arguments, (Policies*)0);

If not, is there another solution how to make sure somebody who writes a script cannot create these issues?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:14:56+00:00Added an answer on June 18, 2026 at 3:14 am

    I solved my issue the following way:

    When im about to delete an object, i iterate through all lua functions from C++ (i have them in a list, they are bound to specific actor objects each). Then i inspect each upvalue (global/local vars accessable to a function) – then i compare the userdata pointer with my object im about to delete – if they match (and their classes) and NIL the upvalue. Optionally, i could just remove that offending function because it would not work well anymore anyway.

    So the next the time the function is called, im just getting a soft lua error “trying to access xxx a nil value…” – no more access violations.

    I know people would say “dont use lua_getupvalue/lua_setupvalue – they are only for debugging!” – but there is actually no documented or spoken side effect – and in my case its perfectly safe and works well – also there isnt the issue with left over proxy objects i could not delete.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since it is possible that a function declared as constexpr can be called during
how is that possible that call to the alert function changes behavior of a
Is it possible that when calling multiple times this function: void Func(String spr, PictureBox
Is it possible that when you have a webpage, when you open the PDF,
It is quite possible that I may not have got the point, but I
It's possible that I'm not really understanding how git works here, but I have
Is it possible that even if I'm using a class from a swc it
It's possible that I'm not really understanding how git works here, but I have
Is it possible that I call Thread.Sleep(1000) and the application may goto sleep for
How is it possible that this function below inserts two rows in my database?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.