Processing 3 settings() method requires size() before setup() in exported Java sketches
0 reputation · 13 Jun 2021, 05:24 UTC
0 reputation · 13 Jun 2021, 05:24 UTC
Migrate a legacy Processing 2 sketch to Processing 3 or later and export it as a Java application while preserving the intended window size and renderer configuration.
Processing 3 moved surface configuration calls such as size(), fullScreen(), smooth(), and pixelDensity() into the optional settings() method, which executes before setup() and before the sketch window is realized. Calling size() inside setup() may silently produce a default 100x100 window or fail at runtime without a compile error. The reference does not explicitly state when default surface values are applied relative to setup(), and behavior may vary by renderer such as P2D or P3D.
Because settings() runs before setup(), state that depends on surface dimensions cannot be initialized there.
setup() to settings() when exporting a Processing 3+ sketch as a Java application?settings() is omitted, and does that timing differ between the default, P2D, and P3D renderers?size() inside setup()?37775 reputation · 13 Jun 2021, 09:33 UTC
setup() to settings()?In Processing 3 and later, all surface configuration calls must be placed in the optional settings() method when exporting as a Java application. This includes:
size(width, height)fullScreen() or fullScreen(displayIndex)smooth(level)pixelDensity(density)size() (e.g., P2D, P3D)Calling any of these in setup() is ignored for surface creation; the sketch window will be created with the default 100×100 size.
settings() is omitted?If settings() is not defined, the default surface dimensions (100×100) are applied immediately before setup() runs. This timing is identical for all renderers — the default JAVA2D, P2D, and P3D. The surface is realized with defaults before any user code in setup() executes.
Because the surface does not exist during settings(), you cannot read width, height, or create PGraphics buffers there. Instead:
settings().setup(), the surface is already created, so width and height reflect the configured size.setup().setup() to defer one-time initialization until after the first frame if you need to guarantee the surface is fully ready.Do not issue drawing commands (e.g., background(), rect()) in settings(); they will have no effect.
size(800, 600) in settings() and println(width, height) in setup(). Export as a Java application and confirm the window is 800×600.size() to setup(), export again, and observe the 100×100 default window.P2D and P3D renderers in settings() to confirm default timing is identical.PGraphics or access pixels[] in their constructors may fail if instantiated before setup(); instantiate them in setup() instead.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.