A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(ads): reject overlapping advertising requests
yhhbc3b8ff200f6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 155cd7000..60ba57dcd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Fixed+- **Advertising requests preserve a single active break.** Rewarded and interstitial requests reject immediately while another ad is showing, before creating a competing unit. The active break retains its showing flag, clock pause and audio suspension until it closes; errors release the guard so a later request can proceed. Rejected requests are not queued for playback.+- **Extreme sprite tile counts reach the bounded fallback on native hosts.** Tile budgets are checked in floating point before converting loop counts to integers, preventing overflowing axes from bypassing the existing 16,384-quad cap. Tiny positive steps retain the single stretched quad; non-finite tile steps and sizes emit no geometry, and grids at the cap remain tiled.- **Sprites retain parent-induced shear in every draw mode.** Ordinary, nine-slice and tiled geometry follows the complete parent transform, and camera bounds use the same basis. Mirrored tiled grids retain positive tile steps before applying signed axes, including the capped fallback. Zero-area sprites skip geometry; existing material, UV and batch state is preserved.diff --git a/sdk/src/services/ads.ts b/sdk/src/services/ads.tsindex 67c92d555..26275109d 100644--- a/sdk/src/services/ads.ts+++ b/sdk/src/services/ads.ts@@ -111,9 +111,11 @@ export class AdsAPI {* Show a rewarded video and resolve with whether the reward was earned —* after the ad closed and the game is running again. Rejects when this* platform has no ad source (check {@link available} first) or the host- * genuinely has no fill; the game state is restored in every path.+ * genuinely has no fill, or another ad is showing; the game state is restored+ * in every path. Overlapping requests are rejected without queuing an ad.*/showRewarded(adUnitId: string): Promise<PlatformRewardedAdResult> {+ if (this.showing_) return Promise.reject(new Error(AdsAPI.ALREADY_SHOWING));const ad = this.rewardedUnit_(adUnitId);if (!ad) return Promise.reject(new Error(AdsAPI.NO_SOURCE));return this.withTakeover_(() => ad.show());@@ -122,11 +124,14 @@ export class AdsAPI {/** Show an interstitial; resolves when it closed. Same contract as* {@link showRewarded}, minus the reward. */showInterstitial(adUnitId: string): Promise<void> {+ if (this.showing_) return Promise.reject(new Error(AdsAPI.ALREADY_SHOWING));const ad = this.interstitialUnit_(adUnitId);if (!ad) return Promise.reject(new Error(AdsAPI.NO_SOURCE));return this.withTakeover_(() => ad.show());}+ private static readonly ALREADY_SHOWING = 'an ad is already showing — wait for it to close before requesting another';+private static readonly NO_SOURCE ='no ad source on this platform — check Ads.available, or install a provider (the editor installs a mock in play mode)';diff --git a/sdk/tests/services-ads.test.ts b/sdk/tests/services-ads.test.tsindex f099aaaab..c7b59c88e 100644--- a/sdk/tests/services-ads.test.ts+++ b/sdk/tests/services-ads.test.ts@@ -100,3 +100,61 @@ describe('AdsAPI takeover ceremony', () => {expect(created).toBe(2);});});+++describe('AdsAPI overlapping requests', () => {+ for (const first of ['rewarded', 'interstitial'] as const) {+ it(`keeps the active ${first} and rejects both competing formats without creating units`, async () => {+ const host = recordingHost();+ const ads = new AdsAPI(createTakeover(host));+ let finish!: () => void;+ let created = 0;+ const pending = new Promise<void>((resolve) => { finish = resolve; });+ ads.setProvider({+ createRewardedAd: () => {+ created++;+ return { preload: async () => {}, show: async () => { await pending; return { completed: true }; }, destroy() {} };+ },+ createInterstitialAd: () => {+ created++;+ return { preload: async () => {}, show: () => pending, destroy() {} };+ },+ });+ const active = first === 'rewarded' ? ads.showRewarded('first') : ads.showInterstitial('first');+ await expect(ads.showRewarded('other')).rejects.toThrow('already showing');+ await expect(ads.showInterstitial('other')).rejects.toThrow('already showing');+ expect(created).toBe(1);+ expect(ads.showing).toBe(true);+ expect(host.paused).toBe(true);+ expect(host.events).toEqual(['pause', 'audio-off']);+ finish();+ await active;+ expect(ads.showing).toBe(false);+ expect(host.events).toEqual(['pause', 'audio-off', 'audio-on', 'unpause']);+ await ads.showRewarded('other');+ expect(created).toBe(2);+ });+ }++ it('accepts another request after a rejected active ad closes', async () => {+ const host = recordingHost();+ const ads = new AdsAPI(createTakeover(host));+ let fail!: (reason: Error) => void;+ let attempts = 0;+ ads.setProvider({+ createRewardedAd: () => ({ preload: async () => {}, show: () => {+ if (++attempts === 1) return new Promise<{ completed: boolean }>((_, reject) => { fail = reject; });+ return Promise.resolve({ completed: true });+ }, destroy() {} }),+ createInterstitialAd: () => { throw new Error('must not create competing unit'); },+ });+ const active = ads.showRewarded('first');+ const rejected = expect(active).rejects.toThrow('no fill');+ await expect(ads.showInterstitial('other')).rejects.toThrow('already showing');+ fail(new Error('no fill'));+ await rejected;+ expect(ads.showing).toBe(false);+ expect(host.paused).toBe(false);+ expect((await ads.showRewarded('first')).completed).toBe(true);+ });+});diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex e922dd002..49ea9ca9e 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';* the reader recognises anyway.*/export const NOTED = {+ 'fix(ads): reject overlapping advertising requests':+ { note: 'Advertising requests preserve a single active break.' },'fix(sprite): enforce tile budgets before integer conversion':{ note: 'Extreme sprite tile counts reach the bounded fallback on native hosts.' },'fix(sprite): preserve affine geometry and mirrored tile grids':