Skip to content

Commit 35d0a3f

Browse files
Function exception_unhandled_handler fixed on HTML5
The problem was during the call to the function the argument being passed was not a valid struct that could be converted into a string on the GML side. To better mimic the Cpp runner added - message, stacktrace, script - members Closes: YoYoGames/GameMaker-Bugs#4437
1 parent 3521c41 commit 35d0a3f

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

scripts/_GameMaker.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,45 @@ function yyUnhandledExceptionHandler( event )
158158
game_end(-1);
159159
} // end if
160160
else {
161-
var ret = g_GMLUnhandledExceptionHandler( undefined, undefined, event.error );
162-
game_end( ret );
161+
// Create a regular expression pattern to split error stack string.
162+
const regexPattern = new RegExp("\n\\s*?at");
163+
164+
let error = event.error;
165+
const message = error.message;
166+
167+
// Split the error stack string into an array of call stack entries and remove leading/trailing spaces.
168+
// The first entry, usually a message or irrelevant info, is omitted.
169+
const stacktrace = error.stack
170+
.split(regexPattern)
171+
.map(entry => entry.trim())
172+
.slice(1);
173+
174+
// Attempt to parse the first call stack entry to identify the script where the error originated.
175+
// The script name is assumed to be the substring before the first space in the entry.
176+
let script = "";
177+
if (stacktrace.length > 0) {
178+
const firstEntry = stacktrace[0];
179+
const firstSpaceIndex = firstEntry.indexOf(' ');
180+
if (firstSpaceIndex !== -1) {
181+
script = firstEntry.substring(0, firstSpaceIndex);
182+
} else {
183+
script = firstEntry;
184+
}
185+
}
186+
187+
// Construct a GML struct to encapsulate the error details.
188+
let errorStruct = { }
189+
errorStruct.__type = "___struct___";
190+
errorStruct.__yyIsGMLObject = true;
191+
192+
// Add error details to the struct with a "gml" prefix for each member.
193+
errorStruct.gmlmessage = message;
194+
errorStruct.gmlstacktrace = stacktrace;
195+
errorStruct.gmlscript = script;
196+
197+
// Pass the error struct to the custom error handler
198+
var ret = g_GMLUnhandledExceptionHandler( undefined, undefined, errorStruct );
199+
game_end( ret );
163200
}
164201
debugger;
165202
return false;

0 commit comments

Comments
 (0)