Skip to content

fix: enter V8 isolate/context scope before editor codegen compile - #221

Merged
Benjamin-Dobell merged 1 commit into
godotjs:mainfrom
hatgg:2-editor-isolate-scope
Jun 13, 2026
Merged

fix: enter V8 isolate/context scope before editor codegen compile#221
Benjamin-Dobell merged 1 commit into
godotjs:mainfrom
hatgg:2-editor-isolate-scope

Conversation

@benpalevsky

Copy link
Copy Markdown
Contributor

Problem

When the editor builds the TypeScript type definitions for your project, it runs a small piece of JavaScript through the V8 engine to compile it. Before V8 can compile anything, the code has to "enter" the right V8 isolate and context — basically telling V8 which JavaScript world to work in.

Two of these code paths forgot that step: the one that builds types for scene nodes (generate_scene_nodes_types) and the one that builds types for resources (generate_resource_types). They entered only a HandleScope, not the Isolate::Scope and Context::Scope. The third path that does the same kind of work (generate_types) enters all three and works fine.

The result: on a cold start, or when you reimport a lot of files at once, the editor crashes (segfault) deep inside V8's compile step.

What this changes

Add the two missing scope guards (v8::Isolate::Scope and v8::Context::Scope) at both sites, in the same positions as the path that already works (generate_types): the Isolate::Scope alongside the existing HandleScope, and the Context::Scope before the compile call. No logic changes — it just adds two stack guards per site, using the same isolate and context the surrounding code already had.

How to verify

Rebuild the engine and trigger a batch reimport (or a cold editor start that regenerates types) to confirm the crash is gone.

A changeset is included.

generate_scene_nodes_types and generate_resource_types compiled a V8 script with only a HandleScope entered, unlike the working generate_types path; on a cold/batch reimport this segfaulted inside v8::Script::Compile. Enter the v8::Isolate::Scope and v8::Context::Scope before compile_function at both sites.
@Benjamin-Dobell

Copy link
Copy Markdown
Member

This is a definite, yes, from me because I have this EXACT same patch locally and I really should have pushed it already, but it's currently sitting atop a local branch with much more dubious commits below it in stack. This regressed in a01cc6d.

@Benjamin-Dobell
Benjamin-Dobell enabled auto-merge (rebase) June 13, 2026 14:15
@Benjamin-Dobell
Benjamin-Dobell merged commit b1d8b3f into godotjs:main Jun 13, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants