'Processing exported application canvas size differs from ide launched application
I have a simple Processing 3 application I just migrated to Processing 4.
The old version had some global variables fine tuned for 1920x1080 displays, so while porting I decided to make it more dynamic and made so that those global variables would depend on displayWidth and displayHeight.
Now when I launch the app through the IDE it works just fine:
However if I export the app (File > Export Application > Windows 64-bit Include Java) this happens:
My card images are svgs so I think it's weird that they look so pixeled, so my guess is that for some reason the canvas is getting the right size but it's also getting stretched.
This is just a guess, I may be completely wrong. Anyway the size is wrong and I'd like to fix that, but I have no idea how.
Can anyone help me?
My code is the following:
//Global variables.
int frameRate = 30;
int cardWidth;
int cardHeight;
int border;
int edge;
int cardsetSpace;
int cardSpace;
int textSize;
int yOffset;
float savedGameWritingDurationLeft = 0;
int loadingWritingDurationLeft = 0;
boolean isLoading = false;
final String loadingWriting = "CARICAMENTO...";
final String savedGameWriting = "PARTITA SALVATA";
//Global variables.
void settings()
{
cardWidth = (int) (displayWidth / 15.36);
cardHeight = (int) (displayHeight / 6.17);
border = cardWidth / 10;
edge = border / 3;
cardsetSpace = border + edge * 2;
cardSpace = (int) (cardHeight / 4.6);
textSize = displayHeight / 54;
yOffset = textSize + 8;
size(cardWidth * 8 + cardsetSpace * 9, cardHeight * 5 + textSize * 2);
}
(The whole code can be found on GitHub, but I think only the above piece is relevant)
EDIT:
I did some more tests and I found out that:
- Both the IDE launched app and the exported app detect
displayWidth
anddisplayHeight
correctly to 2560 and 1440 respectively insidesettings()
. - The IDE launched app detects
displayWidth
anddisplayHeight
correctly also outside ofsettings()
, while the exported app detects 1707 fordisplayWidth
and 960 fordisplayHeight
outside ofsettings()
. - Both apps have width and height to 1562 and 1217 respectively.
- It appears that
displayDensity()
returns 1 when in IDE and 2 when exported. Furthermore if I try to forcepixelDensity()
to 2 when in IDE I get a warning that my display does not support it.
I have no idea why all of this happens, but the issue is now clear: the exported app thinks my 2560x1440 display is actually a 1707x960 display, so when drawing a 1562x1217 canvas it gets huge.
Yes I did try pixelDensity(displayDensity())
but that only resulted in making the exported app canvas even bigger.
Solution 1:[1]
I found out it was due to some bug of Processing 4 (beta 8).
Unfortunately I do not have time nor will to pinpoint the exact issue, however I can share a viable solution I found: downgrading to Processing 3.
Downgrading and re-exporting the app fixed it.
Hopefully this problem will be fixed in a future release of Processing 4.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | CrystalSpider |