Giter Club home page Giter Club logo

Comments (4)

ivan-mogilko avatar ivan-mogilko commented on August 30, 2024

Not long ago I added following safety check for DynamicSprite.Create:

    if (width <= 0 || height <= 0)
    {
        debug_script_warn("WARNING: DynamicSprite.Create: invalid size %d x %d, will adjust", width, height);
        width = std::max(1, width);
        height = std::max(1, height);
    }

IIRC this was done for backwards compatibility.

I believe then same should be added to CreateFromDrawingSurface for consistency.

from ags.

ivan-mogilko avatar ivan-mogilko commented on August 30, 2024

Alright, so what happens here actually is that the bitmap is created with correct color depth, but when trying to put it into a SpriteCache, SpriteCache rejects it as being "size = 0", and the slot remains empty. Next time this sprite is requested, SpriteCache returns a placeholder, which is a 1x1 8-bit image. It looks like it's 8-bit by coincidence.

What needs to be done here is to check the result of setting a sprite into a SpriteCache, and also check whether bitmap is valid earlier when adding a dynamic sprite, and make sure that DynamicSprite.Create... functions return null if something like this happens.

There are actually asserts for width or height being zero in allegro code when a bitmap is created but neither of them are triggered when running in debug for me.

Allegro code allows width to be zero, but requires height to be non-zero:

ASSERT(width >= 0);
ASSERT(height > 0);

EDIT: the "background" in a warning should be replaced with "destination" or "surface", as this code runs for any drawing surface, not just room background.

from ags.

ivan-mogilko avatar ivan-mogilko commented on August 30, 2024

Okay, I pushed 3 small commits in regards to this:
9c54262
83e78fb
9d12250

  • if dynamic sprite could not be added for any reason, the script functions will return null pointer instead of a invalid DynamicSprite object.
  • in DynamicSprite.CreateFrom* functions <= 0 width and height will be automatically fixed to 1, with a warning.

from ags.

ericoporto avatar ericoporto commented on August 30, 2024

Thank you! This fixes. Tried in my actual game and also in my test game. Got the [Game][Warn]: (room:1)[R 14] WARNING: DynamicSprite.CreateFromDrawingSurface: invalid size 0 x 100, will adjust message in the test game.

from ags.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.