Skip to content

Commit

Permalink
Fix local variables default values when the wait action is used
Browse files Browse the repository at this point in the history
  • Loading branch information
D8H committed Jun 25, 2024
1 parent f909675 commit 183e7fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions Core/GDCore/Events/CodeGeneration/EventsCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,14 @@ EventsCodeGenerator::GenerateCallback(
const gd::String actionsDeclarationsCode =
GenerateObjectsDeclarationCode(callbackContext);

const gd::String callbackCode =
callbackFunctionName + " = function (" +
GenerateEventsParameters(callbackContext) + ") {\n" +
restoreLocalVariablesCode +
actionsDeclarationsCode + actionsCode + "}\n";
const gd::String clearLocalVariablesCode =
GenerateLocalVariablesStackAccessor() + ".length = 0;\n";

const gd::String callbackCode = callbackFunctionName + " = function (" +
GenerateEventsParameters(callbackContext) +
") {\n" + restoreLocalVariablesCode +
actionsDeclarationsCode + actionsCode +
clearLocalVariablesCode + "}\n";

AddCustomCodeOutsideMain(callbackCode);

Expand Down
6 changes: 3 additions & 3 deletions GDJS/GDJS/Extensions/Builtin/AsyncExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ AsyncExtension::AsyncExtension() {
gd::BuiltinExtensionsImplementer::ImplementsAsyncExtension(*this);

GetAllEvents()["BuiltinAsync::Async"].SetCodeGenerator(
[](gd::BaseEvent &event_,
gd::EventsCodeGenerator &codeGenerator,
[](gd::BaseEvent &event_, gd::EventsCodeGenerator &codeGenerator,
gd::EventsCodeGenerationContext &parentContext) {
gd::AsyncEvent &event = dynamic_cast<gd::AsyncEvent &>(event_);

Expand Down Expand Up @@ -71,7 +70,8 @@ AsyncExtension::AsyncExtension() {
}

return "{\n" + parentAsyncObjectsListGetter + "{\n" +
asyncContextBuilder + asyncActionCode + "}\n" + "}\n";
asyncContextBuilder + asyncActionCode +
"}\n" + "}\n";
});

GetAllActions()["BuiltinAsync::ResolveAsyncEventsFunction"].SetFunctionName(
Expand Down

0 comments on commit 183e7fc

Please sign in to comment.