From a26e50705c612bbaa79c4b9b8285e4e91e3bcbd2 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 23 Feb 2018 15:10:15 -0800 Subject: [PATCH 1/6] Quick Node.js tool fix --- lime/tools/helpers/HTML5Helper.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lime/tools/helpers/HTML5Helper.hx b/lime/tools/helpers/HTML5Helper.hx index 69970af2a..a3ddfb697 100644 --- a/lime/tools/helpers/HTML5Helper.hx +++ b/lime/tools/helpers/HTML5Helper.hx @@ -214,9 +214,11 @@ class HTML5Helper { if (FileSystem.exists (tempFile + ".map")) { // closure does not include a sourceMappingURL in the created .js, we do it here + #if !nodejs var f = File.append (tempFile); f.writeString ("//# sourceMappingURL=" + Path.withoutDirectory (sourceFile) + ".map"); f.close (); + #end File.copy (tempFile + ".map", sourceFile + ".map"); FileSystem.deleteFile (tempFile + ".map"); From b884a81c86c76982198fb3b0911a3cf89665fd5a Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 23 Feb 2018 15:14:45 -0800 Subject: [PATCH 2/6] cURL fix when being GC'ed --- project/src/net/curl/CURLBindings.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/project/src/net/curl/CURLBindings.cpp b/project/src/net/curl/CURLBindings.cpp index 455a94e73..9e4112cd2 100644 --- a/project/src/net/curl/CURLBindings.cpp +++ b/project/src/net/curl/CURLBindings.cpp @@ -355,6 +355,7 @@ namespace lime { if (method && !val_is_null (method)) { Bytes* _writeBytes = writeBytes[callback]; + if (!_writeBytes) return 0; _writeBytes->Resize (size * nmemb); memcpy (_writeBytes->Data (), ptr, size * nmemb); From 440d0b886603d2c903cd5b8f0ad73561402280d7 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Fri, 23 Feb 2018 22:06:03 -0800 Subject: [PATCH 3/6] Fix openfl.Vector -> typed array conversion (resolve openfl/openfl#1829) --- lime/utils/Float32Array.hx | 5 +++-- lime/utils/Float64Array.hx | 5 +++-- lime/utils/Int16Array.hx | 5 +++-- lime/utils/Int32Array.hx | 5 +++-- lime/utils/Int8Array.hx | 5 +++-- lime/utils/UInt16Array.hx | 5 +++-- lime/utils/UInt32Array.hx | 5 +++-- lime/utils/UInt8Array.hx | 5 +++-- lime/utils/UInt8ClampedArray.hx | 5 +++-- 9 files changed, 27 insertions(+), 18 deletions(-) diff --git a/lime/utils/Float32Array.hx b/lime/utils/Float32Array.hx index 89669411e..a85afdb02 100644 --- a/lime/utils/Float32Array.hx +++ b/lime/utils/Float32Array.hx @@ -22,7 +22,8 @@ package lime.utils; this = new js.html.Float32Array( elements ); } else if(array != null) { this = new js.html.Float32Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Float32Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Float32Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Float32Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Float32Array( untyped view ); } else if(buffer != null) { @@ -81,7 +82,7 @@ public static var hello:Int; this = new ArrayBufferView( elements, Float32 ); } else if(array != null) { this = new ArrayBufferView(0, Float32).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Float32).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Float32).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Float32).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/Float64Array.hx b/lime/utils/Float64Array.hx index b9a1b423b..e0e46a72f 100644 --- a/lime/utils/Float64Array.hx +++ b/lime/utils/Float64Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Float64Array( elements ); } else if(array != null) { this = new js.html.Float64Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Float64Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Float64Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Float64Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Float64Array( untyped view ); } else if(buffer != null) { @@ -79,7 +80,7 @@ package lime.utils; this = new ArrayBufferView( elements, Float64 ); } else if(array != null) { this = new ArrayBufferView(0, Float64).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Float64).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Float64).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Float64).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/Int16Array.hx b/lime/utils/Int16Array.hx index bdb267c2c..6da23ee4d 100644 --- a/lime/utils/Int16Array.hx +++ b/lime/utils/Int16Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Int16Array( elements ); } else if(array != null) { this = new js.html.Int16Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Int16Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Int16Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Int16Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Int16Array( untyped view ); } else if(buffer != null) { @@ -79,7 +80,7 @@ package lime.utils; this = new ArrayBufferView( elements, Int16 ); } else if(array != null) { this = new ArrayBufferView(0, Int16).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Int16).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Int16).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Int16).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/Int32Array.hx b/lime/utils/Int32Array.hx index 11ad418b4..40ee1111b 100644 --- a/lime/utils/Int32Array.hx +++ b/lime/utils/Int32Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Int32Array( elements ); } else if(array != null) { this = new js.html.Int32Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Int32Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Int32Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Int32Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Int32Array( untyped view ); } else if(buffer != null) { @@ -79,7 +80,7 @@ package lime.utils; this = new ArrayBufferView( elements, Int32 ); } else if(array != null) { this = new ArrayBufferView(0, Int32).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Int32).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Int32).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Int32).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/Int8Array.hx b/lime/utils/Int8Array.hx index 69bd34ef9..65f9bcf44 100644 --- a/lime/utils/Int8Array.hx +++ b/lime/utils/Int8Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Int8Array( elements ); } else if(array != null) { this = new js.html.Int8Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Int8Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Int8Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Int8Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Int8Array( untyped view ); } else if(buffer != null) { @@ -77,7 +78,7 @@ package lime.utils; this = new ArrayBufferView( elements, Int8 ); } else if(array != null) { this = new ArrayBufferView(0, Int8).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Int8).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Int8).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Int8).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/UInt16Array.hx b/lime/utils/UInt16Array.hx index 93fd2b41b..29a221ad7 100644 --- a/lime/utils/UInt16Array.hx +++ b/lime/utils/UInt16Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Uint16Array( elements ); } else if(array != null) { this = new js.html.Uint16Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Uint16Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Uint16Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Uint16Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Uint16Array( untyped view ); } else if(buffer != null) { @@ -79,7 +80,7 @@ package lime.utils; this = new ArrayBufferView( elements, Uint16 ); } else if(array != null) { this = new ArrayBufferView(0, Uint16).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint16).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint16).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Uint16).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/UInt32Array.hx b/lime/utils/UInt32Array.hx index 7e21a023b..3e85ea652 100644 --- a/lime/utils/UInt32Array.hx +++ b/lime/utils/UInt32Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Uint32Array( elements ); } else if(array != null) { this = new js.html.Uint32Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Uint32Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Uint32Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Uint32Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Uint32Array( untyped view ); } else if(buffer != null) { @@ -79,7 +80,7 @@ package lime.utils; this = new ArrayBufferView( elements, Uint32 ); } else if(array != null) { this = new ArrayBufferView(0, Uint32).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint32).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint32).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Uint32).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/UInt8Array.hx b/lime/utils/UInt8Array.hx index fb72e6991..2244d02d3 100644 --- a/lime/utils/UInt8Array.hx +++ b/lime/utils/UInt8Array.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Uint8Array( elements ); } else if(array != null) { this = new js.html.Uint8Array( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Uint8Array( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Uint8Array( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Uint8Array( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Uint8Array( untyped view ); } else if(buffer != null) { @@ -79,7 +80,7 @@ package lime.utils; this = new ArrayBufferView( elements, Uint8 ); } else if(array != null) { this = new ArrayBufferView(0, Uint8).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint8).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint8).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Uint8).initTypedArray(view); } else if(buffer != null) { diff --git a/lime/utils/UInt8ClampedArray.hx b/lime/utils/UInt8ClampedArray.hx index 71359451f..dd84c70f7 100644 --- a/lime/utils/UInt8ClampedArray.hx +++ b/lime/utils/UInt8ClampedArray.hx @@ -21,7 +21,8 @@ package lime.utils; this = new js.html.Uint8ClampedArray( elements ); } else if(array != null) { this = new js.html.Uint8ClampedArray( untyped array ); - #if openfl } else if(vector != null) { this = new js.html.Uint8ClampedArray( untyped untyped (vector).__array ); #end + #if (openfl && commonjs) } else if(vector != null) { this = new js.html.Uint8ClampedArray( untyped (vector) ); + #elseif openfl } else if(vector != null) { this = new js.html.Uint8ClampedArray( untyped untyped (vector).data.__array ); #end } else if(view != null) { this = new js.html.Uint8ClampedArray( untyped view ); } else if(buffer != null) { @@ -88,7 +89,7 @@ package lime.utils; this = new ArrayBufferView( elements, Uint8Clamped ); } else if(array != null) { this = new ArrayBufferView(0, Uint8Clamped).initArray(array); - #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint8Clamped).initArray(untyped (vector).__array); #end + #if openfl } else if(vector != null) { this = new ArrayBufferView(0, Uint8Clamped).initArray(untyped (vector).data.__array); #end } else if(view != null) { this = new ArrayBufferView(0, Uint8Clamped).initTypedArray(view); } else if(buffer != null) { From 14ff4649f7a31244e23ccb7c0ae3299aa7835e4e Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 27 Feb 2018 09:00:58 -0800 Subject: [PATCH 4/6] Start trying to improve support for KHR_debug --- project/src/graphics/opengl/OpenGLBindings.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/project/src/graphics/opengl/OpenGLBindings.cpp b/project/src/graphics/opengl/OpenGLBindings.cpp index c14104b13..e47e80457 100644 --- a/project/src/graphics/opengl/OpenGLBindings.cpp +++ b/project/src/graphics/opengl/OpenGLBindings.cpp @@ -183,6 +183,13 @@ namespace lime { } + void GLAPIENTRY gl_debug_callback (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, GLvoid *userParam) { + + puts (message); + + } + + void lime_gl_active_texture (int texture) { glActiveTexture (texture); @@ -1156,6 +1163,16 @@ namespace lime { if (!init) { + if (strcmp (name.__s, "KHR_debug") == 0) { + + #ifdef LIME_GLES + glDebugMessageCallbackKHR ((GLDEBUGPROCARB)gl_debug_callback, NULL); + #elif !defined(HX_MACOS) + glDebugMessageCallback ((GLDEBUGPROCARB)gl_debug_callback, NULL); + #endif + + } + init = true; kind_share (&functionKind, "function"); From 48e556b20cd0e2652b2c940b19e75c41c844bbbc Mon Sep 17 00:00:00 2001 From: Justin Espedal Date: Tue, 27 Feb 2018 12:07:51 -0800 Subject: [PATCH 5/6] Don't return empty string for error output --- lime/tools/helpers/ProcessHelper.hx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lime/tools/helpers/ProcessHelper.hx b/lime/tools/helpers/ProcessHelper.hx index 088f57917..cca91350f 100644 --- a/lime/tools/helpers/ProcessHelper.hx +++ b/lime/tools/helpers/ProcessHelper.hx @@ -380,13 +380,13 @@ class ProcessHelper { } result = process.exitCode (); - process.close (); output = buffer.getBytes ().toString (); if (output == "") { var error = process.stderr.readAll ().toString (); + process.close (); if (result != 0 || error != "") { @@ -422,6 +422,10 @@ class ProcessHelper { }*/ + } else { + + process.close (); + } } From 8943587122a0d2d3304c35516a8c39c169340188 Mon Sep 17 00:00:00 2001 From: Justin Espedal Date: Mon, 26 Feb 2018 20:45:30 -0800 Subject: [PATCH 6/6] Encode sourceMappingURL as a url sourceMappingURL must be encoded as a url. Before Haxe 4.0.0 the filename was directly copied, so if we're using Haxe < 4.0.0, we should manually encode it to avoid an error in the closure compiler. --- lime/tools/helpers/FileHelper.hx | 20 +++++++++++++++++++ lime/tools/helpers/HTML5Helper.hx | 28 ++++++++++++++++++++++++++- lime/tools/helpers/ModuleHelper.hx | 19 ++++-------------- lime/tools/platforms/HTML5Platform.hx | 2 ++ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/lime/tools/helpers/FileHelper.hx b/lime/tools/helpers/FileHelper.hx index 9848edb19..5b4a39e04 100644 --- a/lime/tools/helpers/FileHelper.hx +++ b/lime/tools/helpers/FileHelper.hx @@ -481,6 +481,26 @@ class FileHelper { } + public static function replaceText (source:String, replaceString:String, replacement:String) { + + if (FileSystem.exists (source)) { + + var output = File.getContent (source); + + var index = output.indexOf (replaceString); + + if (index > -1) { + + output = output.substr (0, index) + replacement + output.substr (index + replaceString.length); + File.saveContent (source, output); + + } + + } + + } + + public static function isNewer (source:String, destination:String):Bool { if (source == null || !FileSystem.exists (source)) { diff --git a/lime/tools/helpers/HTML5Helper.hx b/lime/tools/helpers/HTML5Helper.hx index a3ddfb697..1adaa30f7 100644 --- a/lime/tools/helpers/HTML5Helper.hx +++ b/lime/tools/helpers/HTML5Helper.hx @@ -12,6 +12,7 @@ import lime.project.Asset; import lime.project.Haxelib; import lime.project.HXProject; import lime.project.Platform; +import lime.project.Version; import sys.FileSystem; import sys.io.File; @@ -25,6 +26,31 @@ import cpp.vm.Thread; class HTML5Helper { + public static function encodeSourceMappingURL (sourceFile:String) { + + // This is only required for projects with url-unsafe characters built with a Haxe version prior to 4.0.0 + + var filename = Path.withoutDirectory (sourceFile); + + if (filename != StringTools.urlEncode (filename)) { + + var output = ProcessHelper.runProcess ("", "haxe", [ "-version" ], true, true, true, false, true); + var haxeVer:Version = StringTools.trim (output); + + if (haxeVer < ("4.0.0" : Version)) { + + var replaceString = "//# sourceMappingURL=" + filename + ".map"; + var replacement = "//# sourceMappingURL=" + StringTools.urlEncode (filename) + ".map"; + + FileHelper.replaceText (sourceFile, replaceString, replacement); + + } + + } + + } + + public static function generateFontData (project:HXProject, font:Asset):String { var sourcePath = font.sourcePath; @@ -216,7 +242,7 @@ class HTML5Helper { // closure does not include a sourceMappingURL in the created .js, we do it here #if !nodejs var f = File.append (tempFile); - f.writeString ("//# sourceMappingURL=" + Path.withoutDirectory (sourceFile) + ".map"); + f.writeString ("//# sourceMappingURL=" + StringTools.urlEncode (Path.withoutDirectory (sourceFile)) + ".map"); f.close (); #end diff --git a/lime/tools/helpers/ModuleHelper.hx b/lime/tools/helpers/ModuleHelper.hx index f17625ee2..077ca1180 100644 --- a/lime/tools/helpers/ModuleHelper.hx +++ b/lime/tools/helpers/ModuleHelper.hx @@ -203,21 +203,10 @@ class ModuleHelper { public static function patchFile (outputPath:String):Void { - if (FileSystem.exists (outputPath)) { - - var output = File.getContent (outputPath); - - var replaceString = "var $hxClasses = {}"; - var index = output.indexOf (replaceString); - - if (index > -1) { - - output = output.substr (0, index) + "if (!$hx_exports.$hxClasses) $hx_exports.$hxClasses = {};\nvar $hxClasses = $hx_exports.$hxClasses" + output.substr (index + replaceString.length); - File.saveContent (outputPath, output); - - } - - } + var replaceString = "var $hxClasses = {}"; + var replacement = "if (!$hx_exports.$hxClasses) $hx_exports.$hxClasses = {};\nvar $hxClasses = $hx_exports.$hxClasses"; + + FileHelper.replaceText (outputPath, replaceString, replacement); } diff --git a/lime/tools/platforms/HTML5Platform.hx b/lime/tools/platforms/HTML5Platform.hx index c2f44bbec..f129655e9 100644 --- a/lime/tools/platforms/HTML5Platform.hx +++ b/lime/tools/platforms/HTML5Platform.hx @@ -60,6 +60,8 @@ class HTML5Platform extends PlatformTarget { if (noOutput) return; + HTML5Helper.encodeSourceMappingURL (targetDirectory + "/bin/" + project.app.file + ".js"); + if (project.targetFlags.exists ("webgl")) { FileHelper.copyFile (targetDirectory + "/obj/ApplicationMain.js", outputFile);