Disclaimer:
I did some minor coding in C but I'm new to raylib and not used to malloc errors.
I use ralyib on macosx and run the code using the debugger from vscode.
Sometimes it seems to work fine, but when I run it again, I get the error:
| @"main(7293,0x1000dadc0) malloc: Incorrect checksum for freed object 0x10091bc00: probably modified after being freed.\r\n"
@"Corrupt value: 0xbf58296b3ea7cc5c\r\n"
@"main(7293,0x1000dadc0) malloc: *** set a breakpoint in malloc_error_break to debug\r\n"
|
The code used to break on DrawModel()
Then I added the texture because I thought maybe that's the issue, now the code seems to be breaking on the texture line 17.
If I have a breakpoint at line 17, and step through the code, it breaks on the second run of the game loop on line 50.
my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 | #include "raylib.h"
#include "raymath.h"
#define RLIGHTS_IMPLEMENTATION
#include "include/rlight.h"
int main()
{
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib");
// Load model
Model boat = LoadModel("assets/sailboat/hull.obj");
Texture texture = LoadTexture("assets/texel_checker.jpg");
boat.materials[0].maps[MAP_DIFFUSE].texture = texture;
Camera camera = { 0 };
camera.position = (Vector3){ 10.0f, 10.0f, 8.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 60.0f;
camera.type = CAMERA_PERSPECTIVE;
// Load shader and set up some uniforms
Shader shader = LoadShader("data/base_lighting.vs", "data/lighting.fs");
shader.locs[LOC_MATRIX_MODEL] = GetShaderLocation(shader, "matModel");
shader.locs[LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
// Ambient light level
int ambientLoc = GetShaderLocation(shader, "ambient");
SetShaderValue(shader, ambientLoc, (float[4]){ 0.2f, 0.2f, 0.2f, 1.0f }, UNIFORM_VEC4);
Vector3 position = { 0 };
boat.materials[0].shader = shader;
// Using just 1 point lights
CreateLight(LIGHT_POINT, (Vector3){ 0, 2, 6 }, Vector3Zero(), WHITE, shader);
SetCameraMode(camera, CAMERA_ORBITAL);
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
UpdateCamera(&camera);
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Update the light shader with the camera view position
SetShaderValue(shader, shader.locs[LOC_VECTOR_VIEW], &camera.position.x, UNIFORM_VEC3);
BeginMode3D(camera);
DrawModel(boat, position, 1.0f, WHITE);
EndMode3D();
DrawText("This is a raylib example", 10, 40, 20, DARKGRAY);
DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
UnloadModel(boat);
UnloadShader(shader);
UnloadTexture(texture);
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
|