Skip to content

Commit

Permalink
Fix NPE in immediate mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita36078 committed Feb 21, 2018
1 parent bec5b6f commit 73e4f0a
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions app/src/main/java/javax/microedition/lcdui/Canvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ public void surfaceChanged(SurfaceHolder holder, int format, int newwidth, int n
synchronized (paintsync) {
displayWidth = newwidth;
displayHeight = newheight;
updateSize(true);
updateSize();
postEvent(CanvasEvent.getInstance(Canvas.this, CanvasEvent.SIZE_CHANGED, width, height));
}
postEvent(paintEvent);
}
Expand Down Expand Up @@ -344,7 +345,7 @@ public Canvas() {
displayHeight = ContextHolder.getDisplayHeight();
Log.d("Canvas", "Constructor. w=" + displayWidth + " h=" + displayHeight);

updateSize(false);
updateSize();
}

public static void setVirtualSize(int virtualWidth, int virtualHeight, boolean scaleToFit, boolean keepAspectRatio, int scaleRatio) {
Expand Down Expand Up @@ -376,10 +377,8 @@ public void setOverlay(Overlay ov) {

/**
* Обновить размер и положение виртуального экрана относительно реального.
*
* @param post следует ли оповещать об этих изменениях сам холст и картинку двойной буферизации
*/
private void updateSize(boolean post) {
private void updateSize() {
/*
* Превращаем размеры виртуального экрана
* в размеры видимого для мидлета холста.
Expand Down Expand Up @@ -477,15 +476,8 @@ private void updateSize(boolean post) {
RectF screen = new RectF(0, 0, displayWidth, displayHeight);
RectF virtualScreen = new RectF(onX, onY, onX + onWidth, onY + onHeight);

if (post) {
/*
* проверяем, нужно ли создавать новую картинку для двойной буферизации,
* или сгодится старая
*/
if (offscreen == null || offscreen.getWidth() != width || offscreen.getHeight() != height) {
offscreen = Image.createImage(width, height);
}
postEvent(CanvasEvent.getInstance(this, CanvasEvent.SIZE_CHANGED, width, height));
if (offscreen == null || offscreen.getWidth() != width || offscreen.getHeight() != height) {
offscreen = Image.createImage(width, height);
}
if (overlay != null) {
overlay.resize(screen, virtualScreen);
Expand Down

0 comments on commit 73e4f0a

Please sign in to comment.