Skip to content

[Feature/Bug] Wrap Lua C-API execution calls in lua_pcall to prevent editor SIGABRT on runtime script errors #30

Description

@aerixsystem

Summary

Currently, any unhandled runtime Lua error (such as arithmetic on a nil value, passing a nil argument to C++ bound types like Vector2, or indexing a nil table entry) triggers the default lua_atpanic handler. This immediately crashes the entire editor (PANIC: unprotected error in call to Lua API) with Aborted (core dumped).

Because the editor auto-loads the last saved scene and script state on startup, a single Lua typo causes a continuous startup crash loop for the developer.

Expected Behavior

Runtime errors in user Lua scripts should be caught gracefully using lua_pcall or a custom panic/error handler block. The error should print to the editor's Console/Log panel with a standard Lua stack trace, allowing the user to fix the script in real time without the editor crashing.

Actual Behavior

The engine crashes immediately with:
"PANIC: unprotected error in call to Lua API (attempt to perform arithmetic on a nil value)
Aborted"

Steps to Reproduce

  1. Create a 2D scene with a Lua script component.
  2. In the onUpdate(delta) function, attempt an operation involving an uninitialized/nil variable (e.g., pos.x = pos.x + (missing_var * delta) or entity:setPosition(Vector2(nil_var, 100))).
  3. Run the scene.
  4. Observe the editor crashing immediately to the desktop.

Proposed Solution

Wrap calls into the embedded Lua state inside lua_pcall rather than direct lua_call, and redirect error messages to the editor's log output instead of aborting the host process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions