RobLoach / RobLoach/raylib-cpp

Model default constructor does not initialize base Model structure members

Open
#351 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
960
Forks
120
Avg merge
10m
Merged PRs (30d)
1

Description

I've found that raylib::Model class is deraived from ::Model structure.
Whe you instantiate raylib::Model with default constructor no any members of ::Model is initialized, under Visual Studio you got all of members filled with some debug non zero values.
When you try to call ~Model destructor you will try to free memory by invalid pointer.

This Code inserted anywhere in main will cause an error:

{
    raylib::Model model;
    // You'll get an exception on block exit
}

Very quick fix - add base structure initialization like this:

/**
 * Model type
 */
class Model : public ::Model {
public:
    Model() : ::Model{}
    {
        // Nothing.
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the raylib::Model default constructor shown in the issue and inspect how it derives from ::Model. Reproduce the provided local-scope example under Visual Studio, then verify that destroying a default-constructed model no longer attempts to free invalid pointers.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.