Skip to content
Permalink
Browse files

feat(texture): fix dispose texture: not delete glTexture

description
if delete glTexture, will cause bug when redo-undo:
    create texture t1;
    set t1->glTexture to g1;
    copy state to s1;
    dispose t1;
    restore state to s1;

    t1->glTexture is deleted!!!

reason

solution
not delete glTexture when dispose texture
  • Loading branch information...
yyc-git committed May 27, 2019
1 parent 3217b6c commit be455eb49592c2952c1b33eb31ccd11ee9f3921d
@@ -8,7 +8,7 @@ let execJob = (flags, e, stateData) =>

let data = MessageService.getRecord(e);

let state =
/* let state =
data##needDisposedBasicSourceTextureIndexArray
|> WonderCommonlib.ArrayService.reduceOneParam(
(. state, texture) =>
@@ -28,7 +28,7 @@ let execJob = (flags, e, stateData) =>
state,
),
state,
);
); */

StateRenderWorkerService.setState(stateData, state);
e;
@@ -1,7 +1,7 @@
let needDisposeGlTextureMap = (texture, glTextureMap) =>
glTextureMap |> WonderCommonlib.MutableSparseMapService.has(texture);

let disposeGlTextureMap = (texture, gl, glTextureMap) =>
/* let disposeGlTextureMap = (texture, gl, glTextureMap) =>
switch (
glTextureMap |> WonderCommonlib.MutableSparseMapService.get(texture)
) {
@@ -10,7 +10,7 @@ let disposeGlTextureMap = (texture, gl, glTextureMap) =>
glTextureMap |> WonderCommonlib.MutableSparseMapService.deleteVal(texture);
| None => glTextureMap
};
}; */

let addDisposeIndex = (texture, disposedIndexArray) =>
disposedIndexArray |> ArrayService.push(texture);
No changes.
No changes.
@@ -1,6 +1,6 @@
open StateDataMainType;

let disposeBasicSourceTextureGlTextureMap = (texture, state) =>
/* let disposeBasicSourceTextureGlTextureMap = (texture, state) =>
BasicSourceTextureType.(
WorkerDetectMainService.isUseWorker(state) ?
{
@@ -90,7 +90,7 @@ let disposeArrayBufferViewSourceTextureGlTextureMap = (texture, state) =>
};
} :
state;
};
}; */

let disposeNeedAddedSourceArray = (texture, needAddedSourceArray) =>
needAddedSourceArray
@@ -28,11 +28,16 @@ let _disposeData = (texture, textureIndexInTypeArr, state) => {
} as arrayBufferViewSourceTextureRecord =
RecordArrayBufferViewSourceTextureMainService.getRecord(state);

/*
TODO remove related logic:
e.g. needDisposedTextureIndexArray
let state =
state
|> DisposeTextureMainService.disposeArrayBufferViewSourceTextureGlTextureMap(
texture,
);
); */

{
...state,
@@ -26,11 +26,11 @@ let _disposeData = (texture, state) => {
} as basicSourceTextureRecord =
RecordBasicSourceTextureMainService.getRecord(state);

let state =
/* let state =
state
|> DisposeTextureMainService.disposeBasicSourceTextureGlTextureMap(
texture,
);
); */

{
...state,
@@ -1,6 +1,6 @@
open StateDataRenderWorkerType;

let disposeBasicSourceTextureGlTextureMap = (texture, state) => {
/* let disposeBasicSourceTextureGlTextureMap = (texture, state) => {
let gl = DeviceManagerService.unsafeGetGl(. state.deviceManagerRecord);
let (
@@ -44,4 +44,4 @@ let disposeArrayBufferViewSourceTextureGlTextureMap = (texture, state) => {
),
}),
};
};
}; */
@@ -0,0 +1,158 @@
open Wonder_jest;

let _ =
describe("test redo,undo texture", () => {
open Expect;
open Expect.Operators;
open Sinon;

let sandbox = getSandboxDefaultVal();
let state = ref(CreateStateMainService.createState());

beforeEach(() => {
sandbox := createSandbox();
state := TestTool.initWithJobConfig(~sandbox, ());

state :=
state^ |> FakeGlTool.setFakeGl(FakeGlTool.buildFakeGl(~sandbox, ()));
});
afterEach(() => restoreSandbox(refJsObjToSandbox(sandbox^)));

describe("test basic source texture", () =>
describe(
{|
create texture t1;
set t1->glTexture to g1;
copy state to s1;
dispose t1;
restore state to s1;
|},
() => {
let _prepareAndExec = state => {
let (state, texture) =
BasicSourceTextureAPI.createBasicSourceTexture(state^);
let glTexture = Obj.magic(2);
let state =
state |> BasicSourceTextureTool.setGlTexture(texture, glTexture);

let copiedState = StateAPI.deepCopyForRestore(state);

let state =
state
|> BasicSourceTextureAPI.disposeBasicSourceTexture(
texture,
false,
);
let restoredState = MainStateTool.restore(state, copiedState);

(restoredState, texture, glTexture);
};

test("t1->glTexture should be g1", () => {
let (restoredState, texture, glTexture) = _prepareAndExec(state);

BasicSourceTextureTool.unsafeGetTexture(texture, restoredState)
|> expect == glTexture;
});
test("t1->glTexture shouldn't be deleted", () => {
let deleteTexture =
Obj.magic(DeviceManagerAPI.unsafeGetGl(state^))##deleteTexture;

let (restoredState, texture, glTexture) = _prepareAndExec(state);

deleteTexture |> expect |> not_ |> toCalledWith([|glTexture|]);
});
},
)
);

describe("test array buffer view source texture", () =>
describe(
{|
create material m1;
create texture t1, t2;
set t1,t2 to be m1->map;
set t1->glTexture to g1;
set t2->glTexture to g2;
copy state to s1;
dispose m1;
restore state to s1;
|},
() => {
let _prepareAndExec = state => {
let (
state,
material1,
(diffuseMap1, specularMap1, source1_1, source1_2),
) =
LightMaterialTool.createMaterialWithArrayBufferViewMap(state^);
let glTexture1 = Obj.magic(2);
let glTexture2 = Obj.magic(3);
let state =
state
|> ArrayBufferViewSourceTextureTool.setGlTexture(
diffuseMap1,
glTexture1,
);
let state =
state
|> ArrayBufferViewSourceTextureTool.setGlTexture(
specularMap1,
glTexture2,
);

let copiedState = StateAPI.deepCopyForRestore(state);

let state =
LightMaterialAPI.batchDisposeLightMaterial(
[|material1|],
state,
);
let restoredState = MainStateTool.restore(state, copiedState);

(
restoredState,
diffuseMap1,
specularMap1,
glTexture1,
glTexture2,
);
};

beforeEach(() => state := AllMaterialTool.pregetGLSLData(state^));

test("t1->glTexture should be g1", () => {
let (
restoredState,
diffuseMap1,
specularMap1,
glTexture1,
glTexture2,
) =
_prepareAndExec(state);

ArrayBufferViewSourceTextureTool.unsafeGetTexture(
diffuseMap1,
restoredState,
)
|> expect == glTexture1;
});
test("t1->glTexture shouldn't be deleted", () => {
let deleteTexture =
Obj.magic(DeviceManagerAPI.unsafeGetGl(state^))##deleteTexture;

let (
restoredState,
diffuseMap1,
specularMap1,
glTexture1,
glTexture2,
) =
_prepareAndExec(state);

deleteTexture |> expect |> not_ |> toCalledWith([|glTexture1|]);
});
},
)
);
});
@@ -226,7 +226,7 @@ let _ =
(),
);
});
testPromise("send dispose basic source texture data", () => {
/* testPromise("send dispose basic source texture data", () => {
TestMainWorkerTool.closeContractCheck();
let (state, material1, (diffuseMap, specularMap, source1, source2)) =
LightMaterialTool.createMaterialWithMap(state^);
@@ -260,7 +260,7 @@ let _ =
|> resolve,
(),
);
});
}); */
})
);
});

This file was deleted.

0 comments on commit be455eb

Please sign in to comment.
You can’t perform that action at this time.