Skip to content

Commit

Permalink
Provide a better real-world example of the SDL_RWread() API change
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 5, 2023
1 parent 228d9ae commit bb34441
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,22 +545,21 @@ SDL_RWread() previously returned 0 at end of file or other error. Now it returns

Code that used to look like this:
```
if (!SDL_RWread(context, ptr, size, 1)) {
... handle error
}
size_t custom_read(void *ptr, size_t size, size_t nitems, SDL_RWops *stream)
{
return (size_t)SDL_RWread(stream, ptr, size, nitems);
}
```
should be changed to:
```
if (SDL_RWread(context, ptr, size) != size) {
... handle error
}
```
or, if you're using a custom non-blocking context or are handling variable size data:
```
Sint64 amount = SDL_RWread(context, ptr, maxsize);
if (amount < 0) {
... handle error
size_t custom_read(void *ptr, size_t size, size_t nitems, SDL_RWops *stream)
{
Sint64 amount = SDL_RWread(stream, ptr, size * nitems);
if (amount <= 0) {
return 0;
}
return (size_t)(amount / size);
}
```

Similarly, SDL_RWwrite() can return -2 for data not ready in the case of a non-blocking context. There is currently no way to create a non-blocking context, we have simply defined the semantic for your own custom SDL_RWops object.
Expand Down

0 comments on commit bb34441

Please sign in to comment.