Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Aug 8, 2023
1 parent eca7512 commit 19384c8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 27 deletions.
5 changes: 3 additions & 2 deletions cocos/2d/assembler/label/ttfUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const ttfUtils = {
},

updateLayoutData (comp: Label): void {
if (comp.layoutDirty) {
if (comp.layoutDirty && comp.assemblerData) {
const trans = comp.node._uiProps.uiTransformComp!;
const processing = TextProcessing.instance;
const style = comp.textStyle;
Expand All @@ -133,7 +133,7 @@ export const ttfUtils = {
style.fontScale = view.getScaleX();
this.updateLayoutProcessingData(style, layout, outputLayoutData, comp, trans);
// use canvas in assemblerData // to do to optimize
processing.setCanvasUsed(comp.assemblerData!.canvas, comp.assemblerData!.context);
processing.setCanvasUsed(comp.assemblerData.canvas, comp.assemblerData.context);
style.fontFamily = this._updateFontFamily(comp);

// TextProcessing
Expand All @@ -159,6 +159,7 @@ export const ttfUtils = {

this._resetDynamicAtlas(comp);

processing.setCanvasUsed(comp.assemblerData!.canvas, comp.assemblerData!.context);
processing.generateRenderInfo(false, style, layout, outputLayoutData, outputRenderData, comp.string, this.generateVertexData);

const renderData = comp.renderData;
Expand Down
2 changes: 2 additions & 0 deletions cocos/2d/components/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ export class Label extends UIRenderer {
this._applyFontTexture();
}
if (this._assembler) {
this._assembler.updateLayoutData(this);
this._assembler.updateRenderData(this);
}
}
Expand Down Expand Up @@ -914,6 +915,7 @@ export class Label extends UIRenderer {
}
this.changeMaterialForDefine();
if (this._assembler) {
this._assembler.updateLayoutData(this);
this._assembler.updateRenderData(this);
}
}
Expand Down
32 changes: 9 additions & 23 deletions cocos/2d/framework/ui-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,8 @@ import { uiRendererManager } from './ui-renderer-manager';
import { uiLayoutManager } from './ui-layout-manager';
import { Batcher2D } from '../renderer/batcher-2d';

class FunctionCallbackInfo {
public callback: AnyFunction;
public target: any;
constructor (callback: AnyFunction, target: any) {
this.callback = callback;
this.target = target;
}
}

export class UISystem extends System {
private _batcher: Batcher2D | null = null;
private _extraPartBeforeUpdate: FunctionCallbackInfo[] = [];

/**
* @en The draw batch manager for 2D UI, for engine internal usage, user do not need to use this.
Expand All @@ -57,13 +47,20 @@ export class UISystem extends System {
director.on(Director.EVENT_AFTER_SCENE_LAUNCH, this.afterSceneLaunch, this);
director.on(Director.EVENT_BEFORE_UPDATE, this.beforeUpdate, this);
director.on(Director.EVENT_AFTER_UPDATE, this.afterUpdate, this);
director.on(Director.EVENT_BEFORE_DRAW, this.beforeDraw, this);
director.on(Director.EVENT_UPDATE_UI, this.tick, this);
director.on(Director.EVENT_BEFORE_COMMIT, this.render, this);
director.on(Director.EVENT_BEFORE_DRAW, this.beforeDraw, this);
director.on(Director.EVENT_AFTER_DRAW, this.afterDraw, this);
director.on(Director.EVENT_BEFORE_COMMIT, this.render, this);
}

public destroy (): void {
director.off(Director.EVENT_AFTER_SCENE_LAUNCH, this.afterSceneLaunch, this);
director.off(Director.EVENT_BEFORE_UPDATE, this.beforeUpdate, this);
director.off(Director.EVENT_AFTER_UPDATE, this.afterUpdate, this);
director.off(Director.EVENT_UPDATE_UI, this.tick, this);
director.off(Director.EVENT_BEFORE_DRAW, this.beforeDraw, this);
director.off(Director.EVENT_AFTER_DRAW, this.afterDraw, this);
director.off(Director.EVENT_BEFORE_COMMIT, this.render, this);
if (this._batcher) {
this._batcher.destroy();
this._batcher = null;
Expand Down Expand Up @@ -101,17 +98,6 @@ export class UISystem extends System {
}

private beforeDraw (): void {
for (let i = 0, length = this._extraPartBeforeUpdate.length; i < length; i++) {
const info = this._extraPartBeforeUpdate[i];
const callback = info.callback;
const target = info.target;
callback.call(target);
}
this._extraPartBeforeUpdate.length = 0;
}

public addCallbackToBeforeUpdate (callback: AnyFunction, target: any): void {
this._extraPartBeforeUpdate.push(new FunctionCallbackInfo(callback, target));
}
}

Expand Down
2 changes: 1 addition & 1 deletion cocos/tiledmap/assembler/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const simple: IAssembler = {
const device = director.root!.device;
_accessor = new StaticVBAccessor(device, vfmtPosUvColor, this.vCount);
//batcher.registerBufferAccessor(Number.parseInt('TILED-MAP', 36), _accessor);
director.on(Director.EVENT_BEFORE_DRAW, () => { // 额外改造,解除事件依赖,每帧重置
director.on(Director.EVENT_AFTER_UPDATE, () => {
_accessor.reset();
});
}
Expand Down
2 changes: 1 addition & 1 deletion cocos/ui/scroll-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ export class ScrollView extends ViewGroup {
// Because widget component will adjust content position and scrollView position is correct after visit
// So this event could make sure the content is on the correct position after loading.
if (this._content) {
uiSystem.addCallbackToBeforeUpdate(this._adjustContentOutOfBoundary, this);
director.once(Director.EVENT_AFTER_UPDATE, this._adjustContentOutOfBoundary, this);
}
}

Expand Down

0 comments on commit 19384c8

Please sign in to comment.