Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
blurymind opened this issue Jul 21, 2021 · 16 comments
Open

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

blurymind opened this issue Jul 21, 2021 · 16 comments

Comments

@blurymind
Copy link
Contributor

blurymind commented Jul 21, 2021

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

@eXponenta
Copy link
Contributor

eXponenta commented Jul 21, 2021

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

@blurymind
Copy link
Contributor Author

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

@ivanpopelyshev
Copy link
Collaborator

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
Copy link
Collaborator

I honestly didnt think about this case

@blurymind
Copy link
Contributor Author

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

@blurymind
Copy link
Contributor Author

blurymind commented Jul 21, 2021

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

@ivanpopelyshev
Copy link
Collaborator

honestly, i dont know where Renderer is in GDevelop.

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Jul 21, 2021

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

@blurymind
Copy link
Contributor Author

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

@blurymind
Copy link
Contributor Author

blurymind commented Jul 21, 2021

@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
Copy link
Contributor Author

blurymind commented Jul 21, 2021

@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
Copy link
Contributor Author

here is my wip pr btw 4ian/GDevelop#2828

@ivanpopelyshev
Copy link
Collaborator

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?

@blurymind
Copy link
Contributor Author

blurymind commented Jul 21, 2021

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
Copy link
Contributor Author

@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

@eXponenta
Copy link
Contributor

eXponenta commented Jul 22, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants