Skip to content

Commit

Permalink
Fix crash when set window icon
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielBRDeveloper committed Apr 12, 2024
1 parent c6eecb6 commit 73692bf
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
9 changes: 3 additions & 6 deletions src/br/nullexcept/mux/app/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -38,12 +39,8 @@ public static void initialize(Valuable<Activity> 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(){
Expand Down
8 changes: 8 additions & 0 deletions src/br/nullexcept/mux/app/Looper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 9 additions & 12 deletions src/br/nullexcept/mux/core/texel/GlfwWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/br/nullexcept/mux/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void measure() {
}
}

protected Size onMeasureContent() {
protected Size onMeasureContent(int parentWidth, int parentHeight) {
return new Size(0,0);
}

Expand Down
4 changes: 2 additions & 2 deletions src/br/nullexcept/mux/view/ViewGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/br/nullexcept/mux/widget/EditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
4 changes: 2 additions & 2 deletions src/br/nullexcept/mux/widget/ImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/br/nullexcept/mux/widget/TextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit 73692bf

Please sign in to comment.