tilemap icon indicating copy to clipboard operation
tilemap copied to clipboard

newest pixi-tilemap fails with renderer.plugins.tilemap undefined

Open blurymind opened this issue 3 years ago • 16 comments

I am currently in the process of upgrading pixi-tilemap on gdevelop and after updating to the newest version of pixi-tilemap, for some reason it no longer gets added to plugins.

it crashes after I do this https://github.com/blurymind/GDevelop/blob/ldtk-p6/Extensions/TileMap/pixi-tilemap-helper.js#L586

You can test this by changing between the old and the new version of the module.The old one works fine, the new one fails here:

https://github.com/pixijs/tilemap/blob/master/dist/pixi-tilemap.umd.js#L468 and everywhere else, because renderer.plugins.tilemap is undefined

blurymind avatar Jul 21 '21 08:07 blurymind

Tilemap MUST BE registered before renderer initialisation and requred global PIXI context. Look like you has invalid initialisation order. Newest version injects renderer is lazy.

You should register render plugin manually before first use like:

https://github.com/pixijs/tilemap/blob/master/src/TileRenderer.ts#L201

eXponenta avatar Jul 21 '21 08:07 eXponenta

how does one do that on an existing Pixi instance? I dont think I can add it when pixi is initiated

blurymind avatar Jul 21 '21 12:07 blurymind

I dont think I can add it when pixi is initiated

so, pixi-tilemap is included after renderer is created?

renderer.plugins.tilemap = new TileRenderer(renderer);

something like that

ivanpopelyshev avatar Jul 21 '21 12:07 ivanpopelyshev

I honestly didnt think about this case

ivanpopelyshev avatar Jul 21 '21 12:07 ivanpopelyshev

Yes unfortunately because of how the extensions in Gdevelop work, the external library is part of the extension itself

blurymind avatar Jul 21 '21 13:07 blurymind

renderer.plugins.tilemap = new TileRenderer(renderer);

I can access PIXI's global object in gdevelop, but have no idea how to get to the renderer. PIXI.Renderer? thats a constructor, how do you get the current renderer?

this what entry point I have in gdevelop's extension https://github.com/blurymind/GDevelop/blob/ldtk-p6/Extensions/TileMap/JsExtension.js#L534

blurymind avatar Jul 21 '21 13:07 blurymind

honestly, i dont know where Renderer is in GDevelop.

ivanpopelyshev avatar Jul 21 '21 14:07 ivanpopelyshev

You can hack the method render() and if there's no plugin - create one. Just copy it and assign to prototype of whatever class is there.

I think i'll remove TileRenderer completely , make it static, later

ivanpopelyshev avatar Jul 21 '21 14:07 ivanpopelyshev

I think it would be better if I get the renderer from gdevelop itself

blurymind avatar Jul 21 '21 17:07 blurymind

@ivanpopelyshev I managed to redister it as a plugin image

however now there is another problem image

is this because our version of pixi on GD doesnt have utils? I am confused

We do seem to have utils, not sure whats going on

blurymind avatar Jul 21 '21 18:07 blurymind

@ivanpopelyshev I might have discovered a bug. utils appears to be in utils.utils for that line. Changing it to

    	    this.indexBuffer.update(utils.utils.createIndicesForQuads(size,
    	        settings.use32bitIndex ? new Uint32Array(size * 6) : undefined));

seems to fix it for me

blurymind avatar Jul 21 '21 18:07 blurymind

here is my wip pr btw https://github.com/4ian/GDevelop/pull/2828

blurymind avatar Jul 21 '21 18:07 blurymind

Ok, so, apparantly in UMD build referece to utils might be wrong, i have to check it!

Btw, since you are here , tell me, is GDevelop using PIXI.Graphics?

ivanpopelyshev avatar Jul 21 '21 18:07 ivanpopelyshev

could be a better question for @4ian , but I think YES. I can find many references to it https://github.com/4ian/GDevelop/search?q=PIXI.Graphics

blurymind avatar Jul 21 '21 18:07 blurymind

@ivanpopelyshev @4ian interestingly its utils.utils.createIndicesForQuads when I try to use the library from the IDE and its utils.createIndicesForQuads when I do it from the runtime

blurymind avatar Jul 22 '21 15:07 blurymind

@ivanpopelyshev I might have discovered a bug. utils appears to be in utils.utils for that line. Changing it to

    	    this.indexBuffer.update(utils.utils.createIndicesForQuads(size,
    	        settings.use32bitIndex ? new Uint32Array(size * 6) : undefined));

seems to fix it for me

Very strange, because bundler link valid utils to UMD. Look to last argument that passed as utils. it is global.PIXI.utils, where global is context global object (self for worker, global for node, window for browser)

https://github.com/pixijs/tilemap/blob/master/dist/pixi-tilemap.umd.js#L17

eXponenta avatar Jul 22 '21 15:07 eXponenta