diff --git a/src/br/nullexcept/mux/app/Application.java b/src/br/nullexcept/mux/app/Application.java index a339136..d9eae90 100644 --- a/src/br/nullexcept/mux/app/Application.java +++ b/src/br/nullexcept/mux/app/Application.java @@ -3,6 +3,7 @@ import br.nullexcept.mux.C; import br.nullexcept.mux.core.texel.TexelAPI; import br.nullexcept.mux.lang.Valuable; +import br.nullexcept.mux.utils.Log; import br.nullexcept.mux.view.Window; import org.lwjgl.opengles.GLES; @@ -38,12 +39,8 @@ public static void initialize(Valuable creator){ TexelAPI.destroy(); glfwTerminate(); System.gc(); - new Thread(()->{ - try { - Thread.sleep(2000); - } catch (InterruptedException e) {} - System.exit(0); - }).start(); + Looper.sleep(2000,0); // Wait for all services stop + System.exit(0); } private static final void loop(){ diff --git a/src/br/nullexcept/mux/app/Looper.java b/src/br/nullexcept/mux/app/Looper.java index 23497aa..5dba731 100644 --- a/src/br/nullexcept/mux/app/Looper.java +++ b/src/br/nullexcept/mux/app/Looper.java @@ -52,9 +52,17 @@ public void loop(){ } } } + + sleep(0, (int) (Math.random()*400)); } } + public static void sleep(int ms, int nano) { + try { + Thread.sleep(ms, nano); + } catch (Exception e){} + } + public void stop(){ this.stop = true; } diff --git a/src/br/nullexcept/mux/core/texel/GlfwWindow.java b/src/br/nullexcept/mux/core/texel/GlfwWindow.java index 7120a15..31ecca0 100644 --- a/src/br/nullexcept/mux/core/texel/GlfwWindow.java +++ b/src/br/nullexcept/mux/core/texel/GlfwWindow.java @@ -308,20 +308,17 @@ public void setIcon(Drawable icon) { flipY.put(row); } - MemoryUtil.memFree(buffer); flipY.flip(); - if (!destroyed) { - GLFWImage img = GLFWImage.create(); - img.width(canvas.getWidth()); - img.height(canvas.getHeight()); - img.pixels(flipY); - - GLFWImage.Buffer bff = GLFWImage.malloc(1); - bff.put(0, img); - - GLFW.glfwSetWindowIcon(window, bff); - } + Looper.getMainLooper().post(()->{ + if (!destroyed) { + GLFWImage ic = GLFWImage.malloc(); + ic.set(iconSize, iconSize, flipY); + GLFWImage.Buffer stack = GLFWImage.malloc(1); + stack.put(0, ic); + GLFW.glfwSetWindowIcon(window, stack); + } + }); }).start(); } diff --git a/src/br/nullexcept/mux/view/View.java b/src/br/nullexcept/mux/view/View.java index 8411ab5..6fb7d6f 100644 --- a/src/br/nullexcept/mux/view/View.java +++ b/src/br/nullexcept/mux/view/View.java @@ -270,7 +270,7 @@ public void measure() { } } - protected Size onMeasureContent() { + protected Size onMeasureContent(int parentWidth, int parentHeight) { return new Size(0,0); } diff --git a/src/br/nullexcept/mux/view/ViewGroup.java b/src/br/nullexcept/mux/view/ViewGroup.java index 5211471..bce72ae 100644 --- a/src/br/nullexcept/mux/view/ViewGroup.java +++ b/src/br/nullexcept/mux/view/ViewGroup.java @@ -50,7 +50,7 @@ protected boolean measureChild(View child) { if (child instanceof ViewGroup) { ((ViewGroup) child).measureChildren(); } - Size size = child.onMeasureContent(); + Size size = child.onMeasureContent(getMeasuredWidth(), getMeasuredHeight()); Point pos = getChildLocation(child); int left = pos.x - getPaddingLeft(); @@ -133,7 +133,7 @@ public final View getChildAt(int x,int y){ } @Override - protected Size onMeasureContent() { + protected Size onMeasureContent(int parentWidth, int parentHeight) { Size size = new Size(); for (View child: children){ int x = Math.max(0, getChildLocation(child).x - getPaddingLeft()); diff --git a/src/br/nullexcept/mux/widget/EditText.java b/src/br/nullexcept/mux/widget/EditText.java index 8d6263d..4753a5d 100644 --- a/src/br/nullexcept/mux/widget/EditText.java +++ b/src/br/nullexcept/mux/widget/EditText.java @@ -136,7 +136,7 @@ public void setSingleLine(boolean singleLine) { } @Override - protected Size onMeasureContent() { + protected Size onMeasureContent(int parentWidth, int parentHeight) { Size size = new Size(); size.height = Math.round(font().getLineHeight()* Math.max(1, text.getLineCount())); diff --git a/src/br/nullexcept/mux/widget/ImageView.java b/src/br/nullexcept/mux/widget/ImageView.java index f347bed..ad8db2f 100644 --- a/src/br/nullexcept/mux/widget/ImageView.java +++ b/src/br/nullexcept/mux/widget/ImageView.java @@ -54,11 +54,11 @@ public void onDraw(Canvas canvas) { } @Override - protected Size onMeasureContent() { + protected Size onMeasureContent(int parentWidth, int parentHeight) { if (image != null) { return new Size(image.getWidth(), image.getHeight()); } else { - return super.onMeasureContent(); + return super.onMeasureContent(parentWidth, parentHeight); } } } diff --git a/src/br/nullexcept/mux/widget/TextView.java b/src/br/nullexcept/mux/widget/TextView.java index 6c6722b..1c24fb4 100644 --- a/src/br/nullexcept/mux/widget/TextView.java +++ b/src/br/nullexcept/mux/widget/TextView.java @@ -30,7 +30,7 @@ public TextView(Context context, AttributeList attrs) { } @Override - protected Size onMeasureContent() { + protected Size onMeasureContent(int parentWidth, int parentHeight) { Size size = new Size(); FontMetrics metrics = paint.getFontMetrics(); for (String line : lines){