Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 6e2269c

Browse files
runrevmarklivecodeali
authored andcommitted
[[ Bug 18899 ]] Make sure current module is updated
This patch ensures that the current module global is updated whenever a new frame is created on the LCB stack. This fixes an issue with 'image from resource file' not working.
1 parent f468dc6 commit 6e2269c

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

libscript/src/script-bytecode.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,12 @@ struct MCScriptBytecodeOp_Invoke
315315
{
316316
case kMCScriptDefinitionKindHandler:
317317
{
318+
MCScriptModuleRef t_previous = MCScriptSetCurrentModule(t_resolved_instance->module);
318319
ctxt.PushFrame(t_resolved_instance,
319320
static_cast<MCScriptHandlerDefinition *>(t_resolved_definition),
320321
t_result_reg,
321322
t_arguments);
323+
MCScriptSetCurrentModule(t_previous);
322324
}
323325
break;
324326

@@ -526,10 +528,12 @@ struct MCScriptBytecodeOp_InvokeIndirect
526528
{
527529
case kMCScriptDefinitionKindHandler:
528530
{
531+
MCScriptModuleRef t_previous = MCScriptSetCurrentModule(t_handler_instance->module);
529532
ctxt.PushFrame(t_handler_instance,
530533
static_cast<MCScriptHandlerDefinition *>(t_handler_def),
531534
p_result_reg,
532535
p_argument_regs);
536+
MCScriptSetCurrentModule(t_previous);
533537
}
534538
break;
535539

libscript/src/script-instance.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
////////////////////////////////////////////////////////////////////////////////
2828

29-
// This is the module of the most recent LCB stack frame on the current thread's
29+
// This is the module of themost recent LCB stack frame on the current thread's
3030
// stack. It is set before and after a foreign handler call so that the native
3131
// code can get some element of context.
3232
static MCScriptModuleRef s_current_module = nil;
@@ -232,7 +232,9 @@ __MCScriptCallHandlerDefinitionInInstance(MCScriptInstanceRef self,
232232
}
233233
}
234234

235-
MCScriptExecuteContext t_execute_ctxt;
235+
MCScriptModuleRef t_previous = MCScriptSetCurrentModule(self->module);
236+
237+
MCScriptExecuteContext t_execute_ctxt;
236238
t_execute_ctxt.Enter(self,
237239
p_handler_def,
238240
MCMakeSpan(p_arguments, p_argument_count),
@@ -252,6 +254,8 @@ __MCScriptCallHandlerDefinitionInInstance(MCScriptInstanceRef self,
252254
t_cookie);
253255
}
254256
}
257+
258+
MCScriptSetCurrentModule(t_previous);
255259

256260
if (!t_execute_ctxt.Leave())
257261
{
@@ -1277,6 +1281,13 @@ MCScriptModuleRef MCScriptGetCurrentModule(void)
12771281
return s_current_module;
12781282
}
12791283

1284+
MCScriptModuleRef MCScriptSetCurrentModule(MCScriptModuleRef p_module)
1285+
{
1286+
MCScriptModuleRef t_previous = s_current_module;
1287+
s_current_module = p_module;
1288+
return t_previous;
1289+
}
1290+
12801291
////////////////////////////////////////////////////////////////////////////////
12811292

12821293
extern "C" bool MC_DLLEXPORT_DEF MCScriptBuiltinRepeatCounted(uinteger_t *x_count)

libscript/src/script-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,8 @@ struct MCScriptInstance: public MCScriptObject
538538
void *host_ptr;
539539
};
540540

541+
MCScriptModuleRef MCScriptSetCurrentModule(MCScriptModuleRef module);
542+
541543
void
542544
MCScriptDestroyInstance(MCScriptInstanceRef instance);
543545

0 commit comments

Comments
 (0)